尝试使用一个不存在的表时,会得到一个编译时错误,而不是运行时错误。
例如,这里没有异常处理:
SQL> BEGIN
2
3 UPDATE made_up_table
4 SET made_up_column = null;
5
6 exception
7 WHEN OTHERS THEN
8 dbms_output.put_line('123');
9 end;
10 /
UPDATE made_up_table
*
ERROR at line 3:
ORA-06550: line 3, column 8:
PL/SQL: ORA-00942: table or view does not exist
ORA-06550: line 3, column 1:
PL/SQL: SQL Statement ignored
如果使用非空约束创建表
SQL> create table made_up_table(made_up_column number not null);
Table created.
SQL> insert into made_up_table values (0);
1 row created.
然后尝试执行违反约束的更新,会引发异常,并显示错误消息:
SQL> BEGIN
2
3 UPDATE made_up_table
4 SET made_up_column = null;
5
6 exception
7 WHEN OTHERS THEN
8 dbms_output.put_line('123');
9 end;
10 /
123
PL/SQL procedure successfully completed.
SQL>