Skip to content

Instantly share code, notes, and snippets.

@forstie
Created August 29, 2019 16:02
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save forstie/4ac177ae424597bfdc5fe0b42907bf03 to your computer and use it in GitHub Desktop.
Save forstie/4ac177ae424597bfdc5fe0b42907bf03 to your computer and use it in GitHub Desktop.
This example shows how to use dynamic SQL (PREPARE and EXECUTE) to implement a VALUES INTO statement.
create procedure qgpl.values_into (out pout integer)
begin
declare values_into_stmt varchar(1000) ccsid 37;
set values_into_stmt = 'values 1+2+3 into ?';
prepare values_into_query from values_into_stmt;
execute values_into_query using pout;
end;
call qgpl.values_into(?);
-- Note that 6 is returned...
@lae0901
Copy link

lae0901 commented Sep 6, 2019

this is only necessary on prepare and execute? Because parameter markers cannot be used like so:

set  ? = 1 + 2 + 3 ;

or

select    1 + 2 + 3
into       ?
from      sysibm/sysdummy1  

Is there a reason why parameter markers cannot be used with the SET or SELECT INTO statements?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment