SELECT INTO statement
The SELECT INTO statement can be used instead of the SET command if you want to put the output of a query into a variable. You can set one or multiple variables with this statement.
Be sure that the statement returns just one row, otherwise you may will get an runtime error.
Example:
create procedure myproc1 (out v_tabschema varchar(100), out v_tabname varchar(100)) begin select tabschema,tabname into v_tabschema, v_tabname from syscat.tables order by create_time desc fetch first 1 rows only; end!
A similar behaviour is by using the VALUES statement:
create procedure myproc (out v_timestamp timestamp) begin values current timestamp into v_timestamp; end!
Link to the DB2 Information Center: DB2 9.7 DB2 10.1 DB2 10.5