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> 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 ;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26506993/viewspace-2124732/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySql儲存過程—2、第一個MySql儲存過程的建立MySql儲存過程
- MySQL儲存過程詳解 mysql 儲存過程MySql儲存過程
- MySQL儲存過程的建立和使用MySql儲存過程
- 查詢儲存過程報錯資訊儲存過程
- MySQL 5.5 建立儲存過程和函式MySql儲存過程函式
- MySQL儲存過程詳解 mysql 儲存過程linkMySql儲存過程
- mysql 儲存過程MySql儲存過程
- Oracle建立儲存過程Oracle儲存過程
- 恢復MySQL資料庫建立儲存過程是遇到錯誤MySql資料庫儲存過程
- jdbc使用call呼叫儲存過程報錯JDBC儲存過程
- MySQL儲存過程除錯工具-dbForge Studio for MySQLMySql儲存過程除錯
- mysql儲存過程整理MySql儲存過程
- MySQL之儲存過程MySql儲存過程
- [MYSQL -23儲存過程]MySql儲存過程
- MYSQL儲存過程管理MySql儲存過程
- mysql儲存過程例子MySql儲存過程
- mysql的儲存過程MySql儲存過程
- MySQL---------儲存過程MySql儲存過程
- SQL 建立儲存過程PROCEDURESQL儲存過程
- pl/sql developer除錯儲存過程報錯處理SQLDeveloper除錯儲存過程
- 【Mysql】Mysql儲存過程學習MySql儲存過程
- mysql如何呼叫儲存過程MySql儲存過程
- Mysql 儲存過程的使用MySql儲存過程
- mysql儲存過程案例解析MySql儲存過程
- mysql儲存過程詳解MySql儲存過程
- mysql儲存過程的修改MySql儲存過程
- MySQL儲存過程SAVEPOINT ROLLBACK toMySql儲存過程
- laravel建立一個儲存過程Laravel儲存過程
- Mysql 的儲存過程和儲存函式MySql儲存過程儲存函式
- mysql 儲存過程和事件排程MySql儲存過程事件
- plsqlDevloper 儲存過程的除錯SQLdev儲存過程除錯
- 應用儲存過程執行報錯解決方案儲存過程
- oracle 儲存過程執行報錯ORA-12828Oracle儲存過程
- SqlServer儲存過程的建立與使用SQLServer儲存過程
- 用儲存過程動態建立表儲存過程
- Laravel 中使用 MySQL 儲存過程LaravelMySql儲存過程
- MySQL 儲存過程和函式MySql儲存過程函式
- mysql儲存過程的引數MySql儲存過程