“COUNT(*)”附近的语法错误?
问题描述:
我想要做一个互动的存储过程 我的意思是,在执行后用户应输入一个字“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 ;
我得到这个错误:
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;
答
的空间和(*)
之间COUNT
是显著。你应该把它们放在一起,不要留下空间。
SELECT COUNT(*) INTO ...
例外是如果你SET SQL_MODE='IGNORE_SPACE'
。阅读Function Name Parsing and Resolution了解更多详情。
你其他错误是,你忘了FROM
子句中的查询之一:
SELECT Id_Fornitore,Des_Fornitore,Ind_Fornitore WHERE Des_Fornitore = nome_forn;
应该是:
SELECT Id_Fornitore,Des_Fornitore,Ind_Fornitore FROM Fornitori
WHERE Des_Fornitore = nome_forn;
+0
我删除了你所说的空间,,现在我得到了一个不同的错误,指向 - > WHERE Des_Fornitore = nome_forn; SET msg =“记录trovati:”; 谢谢 – Roberto
嗯,确实'SELECT COUNT(*)INTO num_rec FROM Fornitori WHERE Des_Fornitore = nome_forn;'从CLI工作? – 2011-09-22 21:42:42
我是一个初学者..你是什么意思的CLI?...谢谢 – Roberto
好的抱歉,你的意思是从外壳..即使我注释掉这一行东西不顺利无论如何.. – Roberto