If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > DB2 v9.5 script error

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-01-10, 00:34
asdfghjk asdfghjk is offline
Registered User
 
Join Date: May 2010
Posts: 2
Question DB2 v9.5 script error

I have this script running perfectly on DB2 V9.8:

BEGIN
IF NOT EXISTS (SELECT TABNAME FROM SYSCAT.TABLES WHERE TABNAME = 'DUMMY_TBL')
THEN
EXECUTE IMMEDIATE
'CREATE TABLE "DUMMY_TBL" (
"DUMMYID" INTEGER NOT NULL,
"USERNAME" VARCHAR (100) NOT NULL,
"KEYHASHCODE" INTEGER NOT NULL,
"STATUS" INTEGER NOT NULL,
"EXCEPTIONLOG" CLOB (1 M ) NOT LOGGED NOT COMPACT,
"EMAILSTATUS" INTEGER NOT NULL,
"EMAILTYPE" INTEGER NOT NULL,
PRIMARY KEY(DUMMYID))';
END IF;
END@

But I am having an error when run it in DB2v9.5, looks like BEGIN clause is not working for v9.5. I tried changing the clause to BEGIN ATOMIC, and different stuffs but still doesnt work. help please?

TIA!
Reply With Quote
  #2 (permalink)  
Old 06-01-10, 09:16
MarkhamDBA MarkhamDBA is offline
Registered User
 
Join Date: Dec 2008
Location: Toronto, Canada
Posts: 381
I did not know DB2 v9.8 was out.

It is a simple courtesy to display an error when you ask other people to help you fix it.
__________________
DB2 v9.5 ESE on AIX v6.1/ v9./10 on z/OS
Reply With Quote
  #3 (permalink)  
Old 06-01-10, 10:00
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
DB2 V9.8 is the PureScale release (but not sure he has that).
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #4 (permalink)  
Old 06-01-10, 12:24
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
I tried this code - it didn't work on v9.5 fp5, but worked on v9.7 fp2 and v9.8 fp2. Possibly something new was added in v9.7 / v9.8.



Failure:

$ db2 -td@ -vf forum
BEGIN IF NOT EXISTS (SELECT TABNAME FROM SYSCAT.TABLES WHERE TABNAME = 'DUMMY_TBL') THEN EXECUTE IMMEDIATE 'CREATE TABLE "DUMMY_TBL" ( "DUMMYID" INTEGER NOT NULL, "USERNAME" VARCHAR (100) NOT NULL, "KEYHASHCODE" INTEGER NOT NULL, "STATUS" INTEGER NOT NULL, "EXCEPTIONLOG" CLOB (1 M ) NOT LOGGED NOT COMPACT, "EMAILSTATUS" INTEGER NOT NULL, "EMAILTYPE" INTEGER NOT NULL, PRIMARY KEY(DUMMYID))'; END IF; END
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0104N An unexpected token "BEGIN IF NOT EXISTS" was found following
"BEGIN-OF-STATEMENT". Expected tokens may include: "<space>".
SQLSTATE=42601



Success:

$ db2 -td@ -vf forum
BEGIN
IF NOT EXISTS (SELECT TABNAME FROM SYSCAT.TABLES WHERE TABNAME = 'DUMMY_TBL')
THEN
EXECUTE IMMEDIATE
'CREATE TABLE "DUMMY_TBL" (
"DUMMYID" INTEGER NOT NULL,
"USERNAME" VARCHAR (100) NOT NULL,
"KEYHASHCODE" INTEGER NOT NULL,
"STATUS" INTEGER NOT NULL,
"EXCEPTIONLOG" CLOB (1 M ) NOT LOGGED NOT COMPACT,
"EMAILSTATUS" INTEGER NOT NULL,
"EMAILTYPE" INTEGER NOT NULL,
PRIMARY KEY(DUMMYID))';
END IF;
END
DB20000I The SQL command completed successfully.
Reply With Quote
  #5 (permalink)  
Old 06-01-10, 13:35
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
Reply With Quote
  #6 (permalink)  
Old 06-01-10, 23:21
asdfghjk asdfghjk is offline
Registered User
 
Join Date: May 2010
Posts: 2
Hi all,

yup thats the error I am having, If possible, I wanted to create a "generic" script that will work on DB2 v9.5 or higher.
I am trying to create a script that creates a table but check's first if the table already exists.

Since BEGIN is new to DB2 v9.7, I tried using BEGIN ATOMIC I got the following error:


DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0104N An unexpected token "EXECUTE IMMEDIATE" was found following "=
'DUMMY_TBL') THEN ". Expected tokens may include: "<compound_return>". LINE
NUMBER=4. SQLSTATE=42601

SQL0104N An unexpected token "EXECUTE IMMEDIATE" was found following "= 'DUMMY_TBL')
THEN
". Expected tokens may include: "<compound_return> ".


I tried not including EXECUTE IMMEDIATE,

IF NOT EXISTS (SELECT TABNAME FROM SYSCAT.TABLES WHERE TABNAME = 'DUMMY_TBL')
THEN
CREATE TABLE "DUMMY_TBL"(
"DUMMYID" INTEGER NOT NULL,
"USERNAME" VARCHAR (100) NOT NULL,
"KEYHASHCODE" INTEGER NOT NULL,
"STATUS" INTEGER NOT NULL,
"EXCEPTIONLOG" CLOB (1 M ) NOT LOGGED NOT COMPACT,
"EMAILSTATUS" INTEGER NOT NULL,
"EMAILTYPE" INTEGER NOT NULL,
PRIMARY KEY(DUMMYID));
END IF;
END@


I then got this error:

DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0104N An unexpected token "DUMMY_TBL" was found following ") THEN CREATE
TABLE". Expected tokens may include: "<space>". LINE NUMBER=4.
SQLSTATE=42601

SQL0104N An unexpected token "DUMMY_TBL" was found following ")
THEN
CREATE TABLE". Expected tokens may include: "<space> ".


I am new to DB2. I know this is a simple script and I must be missing out something here. Any ideas?

Thanks!
Reply With Quote
  #7 (permalink)  
Old 06-02-10, 08:43
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
Can you use a stored procedure? Something similar to:

CREATE PROCEDURE xxxxx
BEGIN
IF NOT EXISTS (SELECT TABNAME FROM SYSCAT.TABLES WHERE TABNAME = 'DUMMY_TBL')
THEN
CREATE TABLE "DUMMY_TBL" (
"DUMMYID" INTEGER NOT NULL,
"USERNAME" VARCHAR (100) NOT NULL,
"KEYHASHCODE" INTEGER NOT NULL,
"STATUS" INTEGER NOT NULL,
"EXCEPTIONLOG" CLOB (1 M ) NOT LOGGED NOT COMPACT,
"EMAILSTATUS" INTEGER NOT NULL,
"EMAILTYPE" INTEGER NOT NULL,
PRIMARY KEY(DUMMYID));
END IF;
END@


Maybe other people can suggest something else.
Reply With Quote
Reply

Tags
db2

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On