Hi, Exerts...
I have a stored procedure where I am trying to write records to a temporary table. As a first step I want to unconditionally drop the temporary table (it may not exist), then re-create the table based on a z-table table we have. Essentially, I'm after an empty table that is a duplicate layout of one particular table for comparisons later.
I tried a simple DROP TABLE but this it's a showstopper if the table doesn't already exist. I found a way, from here, to create another stored procedure that looks in M_TABLES for the temporary table, and drops it if there's a record for it. I did that. All good.
The problem is that my SP to drop the table will drop it, but the CREATE TABLE that comes next reacts as if it's still there with SAP DBTech JDBC: [288]: cannot use duplicate table name. After several tests, I confirmed the drop-table stored-procedure does work as expected.
I thought maybe I should add a 'commit' but I get a compile error that the feature is not supported.
These next two lines is my code.
CALL "SCHEMA1"."Z_PR_DROP_TABLE"('SCHEMA2', 'ZTB_CV_SCM_AGGR_FRESH');
CREATE TABLE "SCHEMA2"."ZTB_CV_SCM_AGGR_FRESH" AS (select * from "SCHEMA1"."ZTB_CV_SCM_AGGR") WITH NO DATA;
The drop store-procedure:
CREATE PROCEDURE "SCHEMA1".Z_PR_DROP_TABLE (schema_name VARCHAR2(50), table_name VARCHAR2(50))
LANGUAGE SQLSCRIPT
AS
BEGIN
declare sch varchar2(50);
declare tab varchar2(50);
declare cnt int := 0;
sch := trim(upper(:schema_name));
tab := trim(upper(:table_name));
select count(*) into cnt from "PUBLIC"."M_TABLES" where schema_name = :sch and table_name = :tab;
if (:cnt > 0) then
exec 'DROP TABLE '||:sch||'.'||:tab;
end if;
End
My work around is to run the drop-table-stored-procedure manually. I'd prefer to not do that.
Thank you.
Michael Davidson
Message was edited by: Michael Davidson