我正在尝试为我的邮件服务器设置一个 MySQL 函数。MySQL 版本是 5.1.66。
我知道这个查询有什么问题。我也尝试过RETURN DOUBLE
, READS SQL DATA
,DETERMINISTIC
但它们都没有帮助。
我正在使用 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 $$