CapsuleCorpJX
IS-IT--Management
That website documents how to make dynamic sql selects.
However, I'm confused on where I should put the following code (which creates a temp, session specific table):
-- create temporary table to be used by procedure
create global temporary table dyn_sql_t (col varchar(30))
on commit preserve rows;
I think I should put it right before a series of calls to "dyn_sql", i.e.:
[start]
REPLACE PROCEDURE a_procedure_that_use_dyn_sql()
begin
create global temporary table dyn_sql_t (col varchar(30))
on commit preserve rows;
call dyn_sql ('some_t', 'some_col1', 'some_col2', 'some_val2b', resultval);
-- resultval is returned as 'some_val1b'
call dyn_sql ('some_t', 'some_col1', 'some_col2', 'some_val2a', resultval);
-- resultval is returned as 'some_val1a'
call dyn_sql ('some_t', 'some_col1', 'some_col2', 'some_val2c', resultval);
-- resultval is returned as 'some_val1c'
call dyn_sql ('some_t', 'some_col2', 'some_col1', 'some_val1a', resultval);
-- resultval is returned as 'some_val2a'
end;
[stop]
Also, would the session end (and therefore the temp table get deleted) once "a_procedure_that_use_dyn_sql" ends?