sql - DB2, Java: Can not CREATE TABLE conditionally -
i'm trying create table within if-then-else statement in java. here i've tried far:
stmt.execute( "begin if (select tabname syscat.tables tabname = 'kundenkontaktdaten' , tabschema = 'grp35') null " + "create table kundenkontaktdaten(kunden_nr int not null primary key, twitter_id varchar(40), google_id bigint, facebook_id bigint, skype_id varchar(64), telefonnummer varchar(50));" + "else " + "delete kundenkontaktdaten; " + "end if;" + "end");
running 1 following exception:
db2 sql error: sqlcode=-104, sqlstate=42601, sqlerrmc=key;int not null primary;<references_spec>, driver=4.13.80
removing not null , primary key kunden_nr returns following exception:
db2 sql error: sqlcode=-104, sqlstate=42601, sqlerrmc=<ddl-statement>, driver=4.13.80
does has idea how handle one?
greets
most ddl statements, including create table
, cannot compiled in stand-alone compound sql (what might call anonymous block). need execute dynamically:
stmt.execute( "begin if (select tabname syscat.tables tabname = 'kundenkontaktdaten' , tabschema = 'grp35') null " + "execute immediate 'create table kundenkontaktdaten (...)';" + ...
Comments
Post a Comment