"COUNT(*)"附近的语法错误? [英] Syntax error near "COUNT (*)"?

查看:106
本文介绍了"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))
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从Fornitori那里Des_Fornitore = nome_forn;

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(*)之间的空间很大.您应该将它们放在一起,不要留空格.

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

SELECT COUNT(*) INTO ...

如果您SET SQL_MODE='IGNORE_SPACE',则例外.阅读函数名称解析和解析以获取更多详细信息.

Exception is if you SET SQL_MODE='IGNORE_SPACE'. Read Function Name Parsing and Resolution for more details.

您的另一个错误是您忘记了其中一个查询中的FROM子句:

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;

应该是:

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

这篇关于"COUNT(*)"附近的语法错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆