简体   繁体   中英

Error Syntax on Mysql Function

Would like to know what is the error on this syntax since all the sample given is similar with the 1 i try to create

CREATE FUNCTION test(regionCode varchar(5)) RETURNS CHAR(50)
DETERMINISTIC
READ SQL DATA
BEGIN
DECLARE NAME_FOUND CHAR(50);
SELECT 'abc' into NAME_FOUND from dual;
RETURN NAME_FOUND;
END

Thanks for the help.

mysql Functin having only READS SQL DATA not READ SQL DATA,that is the mistake you have done in your function.Please find the link for more details:

https://dev.mysql.com/doc/refman/5.7/en/stored-programs-logging.html

READS SQL DATA explicitly tells to MySQL that the function will ONLY read data from databases, thus, it does not contain instructions that modify data, but it contains SQL instructions that read data (eq SELECT).

DELIMITER $$
CREATE FUNCTION test(regionCode varchar(5)) RETURNS CHAR(50)
DETERMINISTIC
READS SQL DATA
BEGIN
DECLARE NAME_FOUND CHAR(50);
SELECT 'abc' into NAME_FOUND from dual;
RETURN NAME_FOUND;
END
 CREATE FUNCTION test(regionCode varchar(5)) RETURNS CHAR(50)

READS SQL DATA
DETERMINISTIC
BEGIN
DECLARE NAME_FOUND CHAR(50);
SELECT 'abc' into NAME_FOUND from dual;
RETURN NAME_FOUND;
END 

TRY THIS QUERY

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM