MySQL錯誤,儲存過程死迴圈錯誤

2021-06-16 21:22:06 字數 1244 閱讀 5504

寫乙個儲存過程,結果老報錯,提示說是死迴圈錯誤,

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官方文件指出 函式無法用遞迴呼叫

儲存過程可以用遞迴呼叫。但是,預設情況下,是禁用的。

要開啟遞迴呼叫,需要把引數max_sp_recursion_depth設定成非零值。

還有其他一些引數需要調整。

mysql儲存過程之迴圈

1.客戶端建立乙個儲存過程,過程名稱為insert corp loop 2.填寫內容 delimiter drop procedure if exists insert corp loop create definer procedure insert corp loop in loop time ...

mysql 儲存過程 迴圈修改

mysql 迴圈修改 儲存過程 delimiter create procedure my proc begin declare billid int declare moneyorder decimal 10,2 declare stop int default 0 declare my curs...

mysql迴圈(儲存過程)

delimiter drop procedure if exists test create procedure test begin declare i int declare j int set i 11235 set j 02011200 while i 15236 do insert int...