十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
这期内容当中小编将会给大家带来有关MySQL中创建存储过程出现报错如何解决,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
成都创新互联公司基于分布式IDC数据中心构建的平台为众多户提供绵阳电信机房 四川大带宽租用 成都机柜租用 成都服务器租用。
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中创建存储过程出现报错如何解决了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注创新互联行业资讯频道。