Running multiple CREATE..DROP statements in Execute SQL Task
I have a PL-SQL script which contains multiple oracle statements e.g.
DROP TABLE XYZ PURGE;
DROP TABLE PQR PURGE;
CREATE TABLE XYZ AS SELECT * FROM ABC;
CREATE TABLE PQR AS SELECT * FROM LMN;
So, the question is how do I run these statments in one EST instead of creating one EST for one statement..
I tried BEGIN..END..but it is giving me an error:
[Execute SQL Task]
Error: Executing the query "BEGIN
drop table ucsf_find_members purge;
with the following
error: "ORA-06550: line 1, column 7:
PLS-00103: Encountered the symbol "
DROP" when expecting one of the following:
begin case declare exit for goto if loop mod null pragma
raise return select update while with <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe"
Possible failure reasons: Problems
with the query,
"ResultSet" property not
set correctly,
parameters
not
set correctly,
or connection
not established correctly.
drop tab..." failed
If I dont use BEGIN..END and just keep semicolons after every statement, then I am getting following error:
[Execute SQL Task] Error: Executing the query "drop table ucsf_find_members purge;
drop table ucs..." failed with the following error: "ORA-00911: invalid character". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
Thank you!!
February 9th, 2012 12:55pm
One of the answers I got is as follows:
begin
execute immediate 'drop table ABC';
execute immediate 'drop table XYZ';
end;
The above statement is working..
Now the problem is my CREATE TABLE STATEMENT contains
or t1.proper_name_ls like 'Unassig%')
How do I write that in dynamic sql :(
Free Windows Admin Tool Kit Click here and download it now
February 9th, 2012 2:19pm
Got the other problem solved as well..
Just use two single quotes instead of a single quote..
or t1.proper_name_ls like ''Unassig%'')
February 9th, 2012 2:23pm
Hi ,
For writing a dynamic SQL, the escape sequence for a single quote is another single quote.
When you want the output as 'Swapnil','Kothari' from a variable then the first and last quotes should be replaced with 3 quotes and inside the string all the quotes with 2 quotes.
Ex: select '''Swapnil'',''Kothari'''
output: 'Swapnil','Kothari'
Thanks,
Swapnil
Free Windows Admin Tool Kit Click here and download it now
February 10th, 2012 3:10pm