oracle异常处理问题
create or replace procedure sql_ddl is
sqlstr1 varchar2(150);
sqlstr2 varchar2(150);
sqlinstr1 varchar2(150);
begin
sqlstr1 := 'drop table mytest';
execute immediate sqlstr1;
exception
when others then
null;
commit;
sqlstr2 := 'create table mytest(code number(6) not null ,name varchar2(50) )';
execute immediate sqlstr2;
commit;
sqlinstr1 := 'insert into mytest(code,name) values(:code,:name)';
execute immediate sqlinstr1
using 2, 'test';
commit;
end sql_ddl;
上边代码运行时,如果有异常,则异常处理代码及后边的动态语句都能正常执行,而如果没有异常产生,为什么异常前边的代码执行完直接会跳到end 结束程序?
------解决方案--------------------
null;
commit;
sqlstr2 := 'create table mytest(code number(6) not null ,name varchar2(50) )';
execute immediate sqlstr2;
commit;
sqlinstr1 := 'insert into mytest(code,name) values(:code,:name)';
execute immediate sqlinstr1
using 2, 'test';
commit;
这部分都是异常处理的东西,所以异常时执行,没有异常时不会执行