您好,登錄后才能下訂單哦!
這篇文章主要介紹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創建函數時報錯'ERROR 1336 (0A000): Dynamic SQL'怎么辦”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。