Unanswered: Are there any syntax error in this statement?
I am still a bit new to DB2 but I know this syntax should work since I have been into the online documentation several times. But there is apparently still something wrong with it since I can't get it to work despite I have played a lot with it. Are there any apparent syntax error that has to be fixed to get it to work?
IF EXISTS(SELECT 1 FROM syscat.tables WHERE tabschema = 'MYSCHEMA' AND tabname = 'MYTABLE')
DROP TABLE myschema.mytable;
The error if I execute this as one statement looks like this (with a bit free translation of the error text to English):
An unexpected element "myschema" was found after "THEN
DROP TABLE". Expected characters could be "<join_type_without_spec> JOIN <join_oper".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.8.86
I have tried to execute this through a JDBC database connection in eclipse but still without success.
I found following description in
IBM DB2 9.7 for LUW SQL Reference, Volume 2 ---> SQL statements ---> Compound SQL (compiled) ---> Description ---> SQL-statement
The following executable statements are not supported in stand-alone
compound SQL (compiled) statements, but are supported in compound
SQL (compiled) statements used within an SQL function, SQL procedure,
v CREATE of an index, table, or view
v DROP of an index, table, or view
So, you can't execute the code as stand-alone SQL statements.
Put the code in an SQL function or SQL procedure.
Gosh! That was a clear explanation to why it not works and that is not anything I have found in the documentation before. But I'll look at it again to see if I still can get it to work as I want when I have put it into a function or procedure then.