SQL script execution control
I am looking for tips how to cont开发者_运维知识库rol execution of large sql script. It will contain various DDL and DML statement. Mostly I was looking for DDL control.What do I actually mean is, that basically I have a script with multiple DDL statements that are generated from one of our DBs. When I start script it will go through even if there is compilation error or error on create. Thx for any ideas
Do you want to quit after an error ? Here is a few examples. Be sure to check documentation of WHENEVER SQLERROR.
DDL (DML) example:
prompt continues after error
prompt =====================
prompt
create table foo;
prompt quits after error with error code
prompt =================================
prompt
whenever sqlerror exit sql.sqlcode
create table foo;
prompt never gets here
prompt ===============
prompt
quit
PL/SQL subprogram raises an exception:
create or replace function foo return number as
foo_error exception;
begin
raise foo_error;
end;
/
show errors
prompt continues after error
prompt =====================
prompt
select foo from dual;
prompt quits after error with error code
prompt =================================
prompt
whenever sqlerror exit sql.sqlcode
select foo from dual;
prompt never gets here
prompt ===============
prompt
quit
PL/SQL unit compilation fails:
create or replace procedure compile_function (f in varchar2) as
begin
execute immediate 'alter function :f compile' using f;
exception
when others then
raise_application_error(-20000, 'Failed to compile function ' || f);
end;
/
show errors
prompt continues after error
prompt =====================
prompt
create or replace function foo return number as
begin
compilation will fail
end;
/
show errors
exec compile_function('foo')
prompt quits after error with error code
prompt =================================
prompt
whenever sqlerror exit sql.sqlcode
create or replace function foo return number as
begin
compilation will fail
end;
/
show errors
exec compile_function('foo')
prompt never gets here
prompt ===============
prompt
quit
精彩评论