gpt4 book ai didi

sql - mysql 程序错误 ERROR 1304 & ERROR 1305

转载 作者:可可西里 更新时间:2023-11-01 07:06:43 26 4
gpt4 key购买 nike

我是使用程序的新手,似乎无法让我的工作正常进行。我正在使用 MySQL v5.1.36 并在 WAMPP 服务器上使用 MySQL 控制台输入我的代码。如果我去(重新)创建程序。我收到错误 #1304 (42000)。

mysql>  DELIMITER //
mysql>
mysql> CREATE PROCEDURE modx.getCRID (IN x VARCHAR(255),OUT y INT)
-> BEGIN
-> DECLARE y INT;
-> SELECT id INTO y
-> FROM `modx`.coverage_region
-> WHERE `coverage_region`.name = x;
-> END//
ERROR 1304 (42000): PROCEDURE getCRID already exists
mysql>
mysql> DELIMITER ;

但是,如果我尝试使用该过程,我会收到错误 #1305 (42000)。

mysql> USE modx;
Database changed
mysql> SET @crID = modx.getCRID("South East");
ERROR 1305 (42000): FUNCTION modx.getCRID does not exist

如果一个程序存在,另一个程序怎么可能不存在呢?我做错了什么。

最佳答案

我认为问题是

  1. 第一个错误的发生是因为您试图重新创建现有过程。如果你先放弃这个过程,你就不会得到这个错误,
  2. 第二个错误是因为 PROCEDURE 是用 CALL 语句调用的,而 FUNCTION 是作为函数引用调用的,就像在您的代码中一样。您必须定义函数,而不是过程。 ( MySQL documentation ) 说:

The CREATE FUNCTION statement is also used in MySQL to support UDFs (user-defined functions). See Section 21.2, “Adding New Functions to MySQL”. A UDF can be regarded as an external stored function. Stored functions share their namespace with UDFs. See Section 8.2.3, “Function Name Parsing and Resolution”, for the rules describing how the server interprets references to different kinds of functions.

To invoke a stored procedure, use the CALL statement (see Section 12.2.1, “CALL Syntax”). To invoke a stored function, refer to it in an expression. The function returns a value during expression evaluation.

关于sql - mysql 程序错误 ERROR 1304 & ERROR 1305,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3401982/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com