Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
168 views
in Technique[技术] by (71.8m points)

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

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

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...