Hello all,
I’m brand new in DB2. I’m trying to create some procedures but I’m failing. The problem is this: I got a table, where there’s a specific SQL to be run with a parameter ‘?’ which has to be filled:
table name: TASKS
ID
SQL
1
insert into students (firstName, lastName, checkId) select firstName, lastName, ? from kids where age = 18
2
insert into students (firstName, lastName, checkId) select firstName, lastName, ? from kids where sex = ‘female’
3
insert into students (firstName, lastName, checkId) select firstName, lastName, ? from kids where grade = ‘b+’
and so on.
The exercise is:
-
select the ID and SQL from above table;
-
Run the selected SQL but instead of the parameter ‘?’ in the SQL set the value of ID.
This is what I got:
begin
declare idNumber INTEGER;
for std as
select ID idValue, SQL sqltext from TASKS
do
set idNumber = idvalue;
execute immediate sqltext using idNumber;
end;
But i’m still failing. I tried: “execute immediate sqltext :idNumber” and so on, but it doesn’t work. I’ve read about passing variables into sql and parameters ‘?’ but no solution works. I’d be happy anyone explain what’s wrong.
Best regards,
Mike