On 6/14/2019 3:35 AM, Marco Franchini wrote:
I created a script in which I create a stored procedure in which I use an instruction
CREATE GLOBAL TEMPORARY TABLE ...
and then I perform operations on the tables
I use RUNSQLSTM command to execute script:
if the temporary table does not exist RUNSQLSTM return error TABLE xxx not found and the stored procedure is not created
if I create temporary table in QTEMP and I execute script the command ends successfully and the stored procedure is created
is there a way in which I don't have to create the temporary table first ?
Thanks
I run into the same problem. You can work around this by adding a step to
the RUNSQLSTM source to create the temporary table first (you can have
multiple statements in a RUNSQLSTM source member.)
Source:
-- Stmt 1
declare global temporary table my_table
[table definition statement];
-- Stmt 2
create or replace procedure myschema.myprocedure
[procedure definition statement(s)]
If this is submitted to batch, you won't need to worry about the temporary table already existing. If you issue RUNSQLSTM interactively multiple
times, you could handle the possibility of the temporary table already
existing by something like this:
-- Stmt 1
begin
declare continue handler for sqlstate '42710'
truncate qtemp.my_table;
declare global temporary table my_table
[table definition statement];
end;
SQLSTATE 42710 is issued if you try to create an object that already
exists. If the temporary table exists, just clear it (TRUNCATE). The
compound statement will then end, and proceed on to Stmt 2. An alternative would be to switch from DECLARE GLOBAL TEMPORARY TABLE to CREATE OR REPLACE TABLE, which would allow you to dispense with the compound statement:
-- Stmt 1
create or replace table qtemp.my_table
[table definition statement]
on replace
delete rows;
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)