是用execute immediate 执行字符串创建视图,如果创建的视图中不存在引用的对象不存在时候能通过,如果不存在时则不通过,如“create or replace force view vw_a as select * from vw_b ,如果vw_b存在能通过,vw_b不存在时就此跳出,请问题如何解决?
使用force命令是可以创建成功的,但是会有错误,这时你可以捕获错误,如begin execute immediate 'create or replace force view vw_a as select * from vw_b'; exception when others then dbms_output.put_line('vw_a created'); execute immediate 'drop view vw_a'; dbms_output.put_line('vw_a deleted'); end; /
execute immediate 'create or replace force view vw_a as select * from vw_b';
exception
when others then
dbms_output.put_line('vw_a created');
execute immediate 'drop view vw_a';
dbms_output.put_line('vw_a deleted');
end;
/