开发者

Syntax error near "COUNT (*)"?

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开发者_JAVA百科))
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;


The space between COUNT and (*) is significant. You should put them together, don't leave a space.

SELECT COUNT(*) INTO ...

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:

SELECT Id_Fornitore,Des_Fornitore,Ind_Fornitore WHERE Des_Fornitore = nome_forn;

Should be:

SELECT Id_Fornitore,Des_Fornitore,Ind_Fornitore FROM Fornitori
WHERE Des_Fornitore = nome_forn;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜