You Asked
You have define an exception type and named it as invalid_number on execution,your plsql code raises exception invalid_number internally.In this case what should you do in order to handle this kind of situation.
1..Exception when invalid_number.
2.exception when invalid_num or statndard.invalid_num then
3.Oracle will recognize error on it's own and differ
4.None of these.
and Connor said...
Obviously I'd strongly recommend not to overlap the names, because the potential for confusion is just huge. But in PLSQL local scope override global scope as you can see from the examples below
SQL> set serverout on
SQL> declare
2 invalid_number exception;
3 x int;
4 begin
5 dbms_output.put_line('Start');
6
7 select to_number('a') into x from dual;
8 end;
9 /
Start
declare
*
ERROR at line 1:
ORA-01722: invalid number
ORA-06512: at line 7
SQL>
SQL>
SQL> set serverout on
SQL> declare
2 invalid_number exception;
3 x int;
4 begin
5 dbms_output.put_line('Start');
6
7 select to_number('a') into x from dual;
8 exception
9 when invalid_number then
10 dbms_output.put_line('exception caught');
11 end;
12 /
Start
declare
*
ERROR at line 1:
ORA-01722: invalid number
ORA-06512: at line 7
SQL>
SQL>
SQL> set serverout on
SQL> declare
2 invalid_number exception;
3 x int;
4 begin
5 dbms_output.put_line('Start');
6
7 select to_number('a') into x from dual;
8 exception
9 when standard.invalid_number then
10 dbms_output.put_line('exception caught');
11 end;
12 /
Start
exception caught
PL/SQL procedure successfully completed.
SQL>
SQL>
SQL> set serverout on
SQL> declare
2 invalid_number exception;
3 x int;
4 begin
5 dbms_output.put_line('Start');
6 raise invalid_number;
7 select to_number('a') into x from dual;
8 exception
9 when standard.invalid_number then
10 dbms_output.put_line('standard exception caught');
11
12 when invalid_number then
13 dbms_output.put_line('my exception caught');
14 end;
15 /
Start
my exception caught
PL/SQL procedure successfully completed.
SQL>
Is this answer out of date? If it is, please let us know via a Comment