“COUNT (*)”附近有语法错误?

发布于 2024-12-06 07:34:48 字数 801 浏览 0 评论 0原文

我想做一个交互式存储过程 我的意思是,执行后用户应该输入

我写的一个单词,但它不起作用..

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人│生佛魔见 2024-12-13 07:34:48

COUNT(*) 之间的空格很重要。你应该把它们放在一起,不要留空格。

SELECT COUNT(*) INTO ...

例外情况是SET SQL_MODE='IGNORE_SPACE'。有关更多详细信息,请阅读函数名称解析和解析


您的另一个错误是您忘记了查询之一中的 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;

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文