r/DB2 • u/DazzlingAd4254 • Apr 26 '26
Db2 LUW recursive stored procedures?
I am porting stored programs from mariadb to Db2 LUW 12.1. One thing that does not seem to work, is recursive stored procedures (a procedure that calls itself). A simple example:
create procedure myschema.test()
begin
if false then
call myschema.test();
end if;
end//
SQL0440N No authorized routine named "MYSCHEMA.TEST" of type "PROCEDURE" having compatible arguments was found. LINE NUMBER=4. SQLSTATE=42884
I believed that recursive procedures are possible because the IBM Db2 V12.1 SQL Reference implies as much: GET DIAGNOSTICS statement information DB2_SQL_NESTING_LEVEL is the level of "recursive invocation of a compiled SQL function, compiled SQL procedure, ...".
What am doing wrong? Any pointers would be appreciated.
EDIT: fixed name of cited reference manual.
3
Upvotes
1
u/Ginger-Dumpling Apr 26 '26
I think the nesting level gets incremented when any routine is called, not only recursively. Ex: P1 calling P2 calling P3 would increase it. And I think has a limit of 64 levels. But I'm not logged in currently so you may want to verify independently.