MySQL錯誤,儲存過程死迴圈錯誤
阿新 • • 發佈:2019-02-01
寫一個儲存過程,結果老報錯,提示說是死迴圈錯誤,
call core_getparentjob(10,1,@a) Error Code: 1456.
Recursive limit 0 (as set by the max_sp_recursion_depth variable) was exceeded for routine core_getparentjob
怎麼檢查也不知道哪裡出了問題。
不過執行這條語句,SET @@SESSION.max_sp_recursion_depth=25; 設定迴圈深度,至少不報錯。
儲存過程
DELIMITER $$ CREATE DEFINER=`root`@`localhost` PROCEDURE `core_getparentjob`(in jobId int, in xtype int, out tempJobId int) BEGIN DECLARE parentJobId int; DECLARE tt int; DECLARE tc int; set parentJobId = 0; -- Get the parent job id select parentId into parentJobId from core_job ta where ta.ID_ = jobId; -- Get the manager if xtype = 1 then set tc = 0; select count(*) into tc from core_job ta where ta.ID_ = parentJobId and ta.isManager = 1; if tc = 0 and parentJobId > 0 then call core_getparentjob(parentJobId,1, tt); set parentJobId = tt; end if; end if; set tempJobId = parentJobId; select parentJobId; END
MySQL官方文件指出 函式無法用遞迴呼叫
儲存過程可以用遞迴呼叫。但是,預設情況下,是禁用的。
還有其他一些引數需要調整。