MySQL中创建存储过程出现报错如何解决

57次阅读
没有评论

共计 2611 个字符,预计需要花费 7 分钟才能阅读完成。

这期内容当中丸趣 TV 小编将会给大家带来有关 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 ;

上述就是丸趣 TV 小编为大家分享的 MySQL 中创建存储过程出现报错如何解决了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注丸趣 TV 行业资讯频道。

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-08-04发表,共计2611字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)