“COUNT (*)”附近有语法错误?
我想做一个交互式存储过程 我的意思是,执行后用户应该输入
我写的一个单词,但它不起作用..
DELIMITER $$
DROP PROCEDURE IF EXISTS ric_forn$$
CREATE PROCEDURE ric_forn (IN nome_forn VARCHAR(100) , OUT msg VARCHAR(100))
BEGIN
DECLARE num_rec INT;
IF (nome_forn = '') THEN
SET msg = "Attenzione il nome inserito non è valido !";
END IF;
SELECT COUNT (*) INTO num_rec FROM Fornitori WHERE Des_Fornitore = nome_forn;
IF num_rec = 0 THEN
SET msg = "Nessun record trovato !";
ELSE
SELECT Id_Fornitore,Des_Fornitore,Ind_Fornitore WHERE Des_Fornitore = nome_forn;
SET msg = "Records trovati:";
END IF;
END$$
DELIMITER ;
我收到此错误:
您的 SQL 语法有错误;检查手册 与您的 MySQL 服务器版本相对应,以便使用正确的语法 靠近 '*) INTO num_rec FROM Fornitori WHERE Des_Fornitore = nome_forn;
I'd like to do an interactive stored procedure
I mean, after execution the user should type a word
I wrote this but it doesn't work..
DELIMITER $
DROP PROCEDURE IF EXISTS ric_forn$
CREATE PROCEDURE ric_forn (IN nome_forn VARCHAR(100) , OUT msg VARCHAR(100))
BEGIN
DECLARE num_rec INT;
IF (nome_forn = '') THEN
SET msg = "Attenzione il nome inserito non è valido !";
END IF;
SELECT COUNT (*) INTO num_rec FROM Fornitori WHERE Des_Fornitore = nome_forn;
IF num_rec = 0 THEN
SET msg = "Nessun record trovato !";
ELSE
SELECT Id_Fornitore,Des_Fornitore,Ind_Fornitore WHERE Des_Fornitore = nome_forn;
SET msg = "Records trovati:";
END IF;
END$
DELIMITER ;
I get this error:
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near '*) INTO num_rec FROM Fornitori WHERE Des_Fornitore = nome_forn;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
COUNT
和(*)
之间的空格很重要。你应该把它们放在一起,不要留空格。例外情况是
SET SQL_MODE='IGNORE_SPACE'
。有关更多详细信息,请阅读函数名称解析和解析。您的另一个错误是您忘记了查询之一中的
FROM
子句:应该是:
The space between
COUNT
and(*)
is significant. You should put them together, don't leave a space.Exception is if you
SET SQL_MODE='IGNORE_SPACE'
. Read Function Name Parsing and Resolution for more details.Your other error is that you forgot the
FROM
clause in one of your queries:Should be: