Search code examples
stored-procedurescursordb2fetch

Fetch specific columns from cursor into variables in db2 stored procedure


I have written a stored procedure where a cursor holds the results of a select that returns approx 20 columns.

I need to perform additional processing which only needs to look at the values in 3 of the columns so I am looking to fetch only those 3 columns into 3 variables instead of all 20, but I can't seem to get the syntax correct.

E.g.

FETCH cursor1.field1, cursor1.field2, cursor1.field3 INTO variable1, variable2, variable3

Thanks for any help


Solution

  • fetch next from cursor into @a1,@a2,@a3