MySQL 建立函式時報錯'ERROR 1336 (0A000): Dynamic SQL'
建立函式時報錯
mysql> delimiter $$
mysql> CREATE FUNCTION is_SQLScriptReferenceExist (THE_REFERENCE VARCHAR(75), THE_VERSION_LEVEL_TABLE_NAME VARCHAR(75)) RETURNS INTEGER DETERMINISTIC
-> BEGIN
-> DECLARE THE_REFERENCE_LABEL VARCHAR(80);
-> DECLARE CONTINUE HANDLER FOR NOT FOUND
-> BEGIN
-> RETURN 0;
-> END;
-> SELECT concat('select c_reference_label INTO THE_REFERENCE_LABEL from ', THE_VERSION_LEVEL_TABLE_NAME, ' where C_REFERENCE_LABEL = ''', THE_REFERENCE, '''') INTO @stmt;
-> PREPARE STMT FROM @stmt;
-> EXECUTE STMT;
-> /* select c_reference_label into THE_REFERENCE_LABEL from THE_VERSION_LEVEL_TABLE_NAME where C_REFERENCE_LABEL = THE_REFERENCE; */
-> RETURN 1;
-> END$$
ERROR 1336 (0A000): Dynamic SQL is not allowed in stored function or trigger
mysql> delimiter ;
報錯原因:
MySQL函式和觸發器中不允許使用動態函式
可以改寫成儲存過程
mysql> delimiter $$
mysql> CREATE PROCEDURE is_SQLScriptReferenceExist (IN THE_REFERENCE VARCHAR(75), IN THE_VERSION_LEVEL_TABLE_NAME VARCHAR(75), OUT V_RET INT(2))
-> BEGIN
-> DECLARE THE_REFERENCE_LABEL VARCHAR(80);
-> DECLARE CONTINUE HANDLER FOR NOT FOUND
-> BEGIN
-> SET V_RET = 0;
-> END;
-> SELECT concat('select c_reference_label INTO THE_REFERENCE_LABEL from ', THE_VERSION_LEVEL_TABLE_NAME, ' where C_REFERENCE_LABEL = ''', THE_REFERENCE, '''') INTO @stmt;
-> PREPARE STMT FROM @stmt;
-> EXECUTE STMT;
-> /* select c_reference_label into THE_REFERENCE_LABEL from THE_VERSION_LEVEL_TABLE_NAME where C_REFERENCE_LABEL = THE_REFERENCE; */
-> SET V_RET = 1;
-> END$$
Query OK, 0 rows affected (0.00 sec)
mysql> delimiter ;
mysql> delimiter $$
mysql> CREATE FUNCTION is_SQLScriptReferenceExist (THE_REFERENCE VARCHAR(75), THE_VERSION_LEVEL_TABLE_NAME VARCHAR(75)) RETURNS INTEGER DETERMINISTIC
-> BEGIN
-> DECLARE THE_REFERENCE_LABEL VARCHAR(80);
-> DECLARE CONTINUE HANDLER FOR NOT FOUND
-> BEGIN
-> RETURN 0;
-> END;
-> SELECT concat('select c_reference_label INTO THE_REFERENCE_LABEL from ', THE_VERSION_LEVEL_TABLE_NAME, ' where C_REFERENCE_LABEL = ''', THE_REFERENCE, '''') INTO @stmt;
-> PREPARE STMT FROM @stmt;
-> EXECUTE STMT;
-> /* select c_reference_label into THE_REFERENCE_LABEL from THE_VERSION_LEVEL_TABLE_NAME where C_REFERENCE_LABEL = THE_REFERENCE; */
-> RETURN 1;
-> END$$
ERROR 1336 (0A000): Dynamic SQL is not allowed in stored function or trigger
mysql> delimiter ;
報錯原因:
MySQL函式和觸發器中不允許使用動態函式
可以改寫成儲存過程
mysql> delimiter $$
mysql> CREATE PROCEDURE is_SQLScriptReferenceExist (IN THE_REFERENCE VARCHAR(75), IN THE_VERSION_LEVEL_TABLE_NAME VARCHAR(75), OUT V_RET INT(2))
-> BEGIN
-> DECLARE THE_REFERENCE_LABEL VARCHAR(80);
-> DECLARE CONTINUE HANDLER FOR NOT FOUND
-> BEGIN
-> SET V_RET = 0;
-> END;
-> SELECT concat('select c_reference_label INTO THE_REFERENCE_LABEL from ', THE_VERSION_LEVEL_TABLE_NAME, ' where C_REFERENCE_LABEL = ''', THE_REFERENCE, '''') INTO @stmt;
-> PREPARE STMT FROM @stmt;
-> EXECUTE STMT;
-> /* select c_reference_label into THE_REFERENCE_LABEL from THE_VERSION_LEVEL_TABLE_NAME where C_REFERENCE_LABEL = THE_REFERENCE; */
-> SET V_RET = 1;
-> END$$
Query OK, 0 rows affected (0.00 sec)
mysql> delimiter ;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26506993/viewspace-2124763/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL建立觸發器時報錯Error Code: 1064MySql觸發器Error
- 測試dns時報Error: Dynamic update is not enabledDNSError
- MySQL 授權時報錯 ERROR 1819MySqlError
- MySQL建立自定義函式MySql函式
- MySQL create function時報錯MySqlFunction
- Mysql與Sql Server DATEDIFF函式MySqlServer函式
- 關於使用toFixed()函式時報錯”toFixed() is not a function”的問題函式Function
- sql server 建立內聯表值函式SQLServer函式
- Xtrabackup恢復時報錯'Error: datadir must be specified'Error
- 【AutoCAD .NET】建立Hatch時報錯eInvalidInput
- 建立函式函式
- count函式與order by子句一起查詢時報錯處理函式
- MySQL 5.5 建立儲存過程和函式MySql儲存過程函式
- MySQL error 錯 誤 碼MySqlError
- SQL Server建立使用者函式與應用SQLServer函式
- 匯入sql時報日期型別錯誤SQL型別
- SQL server開啟 安裝包時報錯SQLServer
- MySQL 5.6修復從庫複製時報錯'ERROR 1872 (HY000): Slave failed to initialize'MySqlErrorAI
- MySQL 5.6初始化資料庫時報錯FATAL ERROR: Could not find ./bin/my_print_defaultsMySql資料庫Error
- SQL函式之日期函式SQL函式
- sql函式SQL函式
- 【SQL】19 SQL函式SQL函式
- MYSQL SOURCE報錯 ERROR: ASCIIMySqlErrorASCII
- 啟動mysql時報錯的解決(mysql 5.0.45 redhat as 43)MySqlRedhat
- ORA-17629:rman建立 standby資料庫時報錯資料庫
- ubuntu進行make時報錯error: Neither flex nor lex was found.UbuntuErrorFlex
- 使用SRVCTL時報錯:error while loading shared librariesErrorWhile
- PL/SQL Developer啟動時報錯,Initialization error could not load xxxx\oci.dllSQLDeveloperError
- why use dynamic SQL?SQL
- MySQL 函式MySql函式
- MySQL函式MySql函式
- 【Mysql】Last_SQL_Error: 1594MySqlASTError
- MySQL建立隨機生成電話的儲存函式MySql隨機儲存函式
- MySQL(四)日期函式 NULL函式 字串函式MySql函式Null字串
- SQL--函式SQL函式
- sql 日期函式SQL函式
- MySql中SUM函式計算錯誤問題MySql函式
- 建立聯合函式索引解決top sql效能問題函式索引SQL