-1

我正在尝试为我的邮件服务器设置一个 MySQL 函数。MySQL 版本是 5.1.66。

我知道这个查询有什么问题。我也尝试过RETURN DOUBLE, READS SQL DATADETERMINISTIC但它们都没有帮助。

我正在使用 PhpMyAdmin。分隔符设置为 $$。但我得到的只是一条神秘的错误信息:

#1064 - 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 'TEXT CHARSET utf8 READS SQL DATA BEGIN DECLARE mygoto VARCHAR(25' at line 3

我的代码:

CREATE PROCEDURE `get_email_alias`(
myemail VARCHAR(255)
) RETURNS TEXT CHARSET utf8
READS SQL DATA

BEGIN

DECLARE mygoto VARCHAR(255);
DECLARE sdomain VARCHAR(255);
DECLARE ddomain VARCHAR(255);

SELECT SUBSTRING(myemail, INSTR(myemail, '@')+1) INTO sdomain;

SELECT target_domain
FROM alias_domain
WHERE alias_domain = sdomain
AND active = 1
LIMIT 1
INTO ddomain;

IF ddomain IS NOT NULL THEN
SELECT REPLACE(myemail, sdomain, ddomain) INTO myemail;
END IF;
SELECT goto
FROM alias
WHERE address = myemail
AND active = 1
LIMIT 1
INTO mygoto;

IF mygoto IS NOT NULL THEN
RETURN mygoto;
END IF;

RETURN null;
END $$
4

2 回答 2

2

对于以后遇到此问题的任何人:

关键字中最初存在语法错误PROCEDURE。它错过了决赛E

根据 MySQL 语法,CREATE PROCEDURE没有RETURN. 但是,CREATE FUNCTION确实允许RETURN在语法中。参考:http ://dev.mysql.com/doc/refman/5.1/en/create-procedure.html 。

于 2013-07-09T19:29:38.523 回答
0

第一行的 PROCEDURE" 缺少 "E"

于 2013-07-09T18:56:11.013 回答