这期内容当中小编将会给大家带来有关MySQL中创建存储过程出现报错如何解决,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
mysql> delimiter $$
mysql> CREATE FUNCTION check_rollbackPatch(THE_REFERNCE_LABEL VARCHAR(75), THE_COLUMN_NAME VARCHAR(75), THE_INSTALL_VERSION VARCHAR(75), THE_VERSION_LEVEL_TABLE_NAME VARCHAR(75))
-> RETURNS INTEGER DETERMINISTIC
-> BEGIN
-> DECLARE INSTALL_VERSION VARCHAR(80) DEFAULT NULL;
-> DECLARE REFERENCE_LABEL VARCHAR(80) DEFAULT NULL;
-> DECLARE THE_QUERY VARCHAR(500) DEFAULT NULL;
-> DECLARE too_many_rows CONDITION FOR 1172;
-> DECLARE CONTINUE HANDLER FOR too_many_rows
-> BEGIN
-> SELECT concat('[INFO] Several ', THE_REFERNCE_LABEL, ' references found.');
-> RETURN 0;
-> END;
-> DECLARE CONTINUE HANDLER FOR NOT FOUND
-> BEGIN
-> /*SELECT concat('[INFO] ', THE_REFERNCE_LABEL, ' reference not found.');*/
-> RETURN 1;
-> END;
-> SELECT concat('', THE_COLUMN_NAME, ', C_INSTALL_VERSION') INTO @V_PART1;
-> SELECT concat(THE_COLUMN_NAME, '=''', THE_REFERNCE_LABEL, ''' and C_INSTALL_VERSION=''', THE_INSTALL_VERSION, '''') INTO @V_PART2;
-> SELECT format_selectQuery(THE_VERSION_LEVEL_TABLE_NAME, @V_PART1, @V_PART2) INTO THE_QUERY;
-> /*SELECT concat('[INFO] The query to execute is [', THE_QUERY, ']');*/
-> /*EXECUTE IMMEDIATE THE_QUERY into REFERENCE_LABEL, INSTALL_VERSION;*/
-> /*SELECT concat('[INFO] ', THE_REFERNCE_LABEL, ' reference found');*/
-> RETURN 0;
-> END $$
ERROR 1415 (0A000): Not allowed to return a result set from a function
mysql> delimiter ;
报错原因:
在MySQL的function里,不能使用SELECT语句来返回结果集,会报错。
注释掉后,报错消失
mysql> delimiter $$
mysql> CREATE FUNCTION check_rollbackPatch(THE_REFERNCE_LABEL VARCHAR(75), THE_COLUMN_NAME VARCHAR(75), THE_INSTALL_VERSION VARCHAR(75), THE_VERSION_LEVEL_TABLE_NAME VARCHAR(75))
-> RETURNS INTEGER DETERMINISTIC
-> BEGIN
-> DECLARE INSTALL_VERSION VARCHAR(80) DEFAULT NULL;
-> DECLARE REFERENCE_LABEL VARCHAR(80) DEFAULT NULL;
-> DECLARE THE_QUERY VARCHAR(500) DEFAULT NULL;
-> DECLARE too_many_rows CONDITION FOR 1172;
-> DECLARE CONTINUE HANDLER FOR too_many_rows
-> BEGIN
-> /*SELECT concat('[INFO] Several ', THE_REFERNCE_LABEL, ' references found.');*/
-> RETURN 0;
-> END;
-> DECLARE CONTINUE HANDLER FOR NOT FOUND
-> BEGIN
-> /*SELECT concat('[INFO] ', THE_REFERNCE_LABEL, ' reference not found.');*/
-> RETURN 1;
-> END;
-> SELECT concat('', THE_COLUMN_NAME, ', C_INSTALL_VERSION') INTO @V_PART1;
-> SELECT concat(THE_COLUMN_NAME, '=''', THE_REFERNCE_LABEL, ''' and C_INSTALL_VERSION=''', THE_INSTALL_VERSION, '''') INTO @V_PART2;
-> SELECT format_selectQuery(THE_VERSION_LEVEL_TABLE_NAME, @V_PART1, @V_PART2) INTO THE_QUERY;
-> /*SELECT concat('[INFO] The query to execute is [', THE_QUERY, ']');*/
-> /*EXECUTE IMMEDIATE THE_QUERY into REFERENCE_LABEL, INSTALL_VERSION;*/
-> /*SELECT concat('[INFO] ', THE_REFERNCE_LABEL, ' reference found');*/
-> RETURN 0;
-> END $$
Query OK, 0 rows affected (0.00 sec)
mysql> delimiter ;
上述就是小编为大家分享的MySQL中创建存储过程出现报错如何解决了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。