All,
I am using DB2, IBM Data Studio Release 2.2.1.0.
Putting my hands on to stored proc development, here is an issue I face.
Assume other parts of a Stored Procedure's body are present and absolutely compilable.
I am declaring a CURSOR
like below
DECLARE cursor1 CURSOR WITH RETURN FOR
SELECT * FROM TBL_1;
OPEN cursor1;
declare continue handler for not found set v_found_flg = 'N';
Above deploys absolutely fine.
But when I attempt to change above to a dynamic cursor, like below.
DECLARE e_msg varchar(400);
DECLARE cursor1 CURSOR WITH RETURN FOR s2;
SET e_msg = 'SELECT * FROM TBL_1';
PREPARE s2 FROM e_msg;
OPEN cursor1;
declare continue handler for not found set v_found_flg = 'N';
It is a simple change above, but I get an error on the line next to "OPEN cursor1", says expecting TOKEN. Note: I have not changed any other part of the existing stored procedure. All I did are :
1. added a varchar declaration
2. changed the declare cursor line
3. added a new line of code --> the set e_msg line
4. added another new line of code, the prepare line you see above
Have no clue what I've not done rightly.