plsql - Anonymous PL/SQL block checked exception -
i'm trying catch exception within anonymous pl/sql block
declare ... begin herstell_row in ( ... ) loop ... declare table_does_not_exists exception; pragma exception_init( table_does_not_exists, -942 ); begin insert smart_monitoring_machine_nav_b ( machine, navigation_level_id ) select old_binding.machine, pv_id smart_machine_nav_binding old_binding old_binding.navigation_level_id = herstell_row.hename1; exception when table_does_not_exists null; end; end loop; end;
i know table smart_machine_nav_binding doesn't exist in case, need nested anonymous block ignore code. error:
error report - ora-06550: line 41, column 14: pl/sql: ora-00942: table or view not exist ora-06550: line 33, column 10: pl/sql: sql statement ignored
you can't compile code non-existent table, can try execute using execute emmediate
:
declare ... begin herstell_row in ( ... ) loop ... declare table_does_not_exists exception; pragma exception_init( table_does_not_exists, -942 ); begin execute immediate 'insert smart_monitoring_machine_nav_b ( machine, navigation_level_id ) select old_binding.machine, pv_id smart_machine_nav_binding old_binding old_binding.navigation_level_id = :p' using herstell_row.hename1; exception when table_does_not_exists null; end; end loop; end;
also don't need exceptions here, can check existence of table using system view:
declare table_created number; begin select count(*) table_created all_tables table_name = ... , owner = ...; if table_created > 0 execute immediate 'insert ...'; end if; end;
more information execute immediate
statement: http://docs.oracle.com/cd/e11882_01/appdev.112/e25519/executeimmediate_statement.htm#lnpls01317
Comments
Post a Comment