mysql程序错误ERROR 1304&错误1305 [英] Error with mysql procedures ERROR 1304 & ERROR 1305

查看:1941
本文介绍了mysql程序错误ERROR 1304&错误1305的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am new to using procedures and cannot seem to get mine working. I am using MySQL v5.1.36 and inputing my code using MySQL Console on a WAMPP server. If I go to (re)create the procedure. I get error #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).

However, if I try to use the procedure I get error #1305 (42000).

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

如果一个程序存在,那么另一程序不存在?我在做什么错了.

If the procedure exists for one how can it not exist for the other? What am I doing wrong.

推荐答案

我相信问题是

  1. 发生第一个错误是因为您试图重新创建现有过程.如果要先删除该过程,则不会出现此错误,
  2. 第二个错误是因为PROCEDURE是用CALL语句调用的,而FUNCTION是作为函数引用调用的,就像在代码中一样.您必须定义一个功能,而不是一个过程. ( MySQL文档)说:
  1. The first error occurs because you are attempting to re-create an existing procedure. If you were to drop the procedure first you would not get this error,
  2. The second error is because PROCEDUREs are invoked with CALL statements, while FUNCTIONs are invoked as function references, as in your code. You must define a FUNCTION, not a PROCEDURE. The (MySQL documentation) says:

CREATE FUNCTION语句也是 在MySQL中使用以支持UDF (用户定义的函数).见章节 21.2,向MySQL添加新功能". UDF可以视为外部 存储功能.存储的功能 与UDF共享其名称空间.看 第8.2.3节函数名称解析" 和解决方案",以了解规则 描述服务器如何解释 提及不同种类的 功能.

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.

要调用存储过程,请使用 CALL陈述式(请参阅第12.2.1节, 致电语法").调用存储的 功能,请参阅 表达.该函数返回一个 评估表达式时的值.

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.

这篇关于mysql程序错误ERROR 1304&错误1305的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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