How to call stored procedure inside another stored procedure and set the values as in variable in DB2

﹥>﹥吖頭↗ 提交于 2019-12-12 06:47:58

问题


I need to call stored procedure into another stored procedure and return value stored in variable in db2.

Thanks


回答1:


One examples could be this one:

 DECLARE STMT STATEMENT;
 PREPARE STMT FROM 'CALL MODIFY_DESCENDANTS (?, ?)';
 EXECUTE STMT USING LOG_ID, LEVEL;

Taken from log4db2 - https://github.com/angoca/log4db2/blob/master/src/main/sql-pl/03-UtilityBody.sql#L729

If the stored procedure returns a result set, and you want to take values from that, then you need to call the stored procedure and use the associate and allocate statements. For an example, you can visit https://www.toadworld.com/platforms/ibmdb2/w/wiki/7460.call-allocate-and-associate

CALL EMPR;
ASSOCIATE RESULT SET LOCATOR (LOC1) WITH PROCEDURE EMPR;
ALLOCATE C1 CURSOR FOR RESULT SET LOC1;


来源:https://stackoverflow.com/questions/41457081/how-to-call-stored-procedure-inside-another-stored-procedure-and-set-the-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!