5. SQL> create or replace procedure P is
2 x int;
3 y int;
4 begin
5
6 x := 10;
7
8 select count(*)
9 into y
10 from all_objects
11 where object_name = 'NUFFIN';
12
13 x := x / y;
14
15 select rownum
16 into x
17 from dual;
18
19 end;
20 /
Procedure created.
6. SQL> exec P;
BEGIN P; END;
*
ERROR at line 1:
ORA-01476: divisor is equal to zero
ORA-06512: at "SCOTT.P", line 13
ORA-06512: at line 1
7. SQL> create or replace procedure P is
2 x int;
3 y int;
4 begin
5
6 x := 10;
7
8 select count(*)
9 into y
10 from all_objects
11 where object_name = 'NUFFIN';
12
13 x := x / y;
14
15 select rownum
16 into x
17 from dual;
18
19 end;
20 /
Procedure created.
9. SQL> create or replace procedure P is
2 x int;
3 y int;
4 begin
5
6 x := 10;
7
8 select count(*)
9 into y
10 from all_objects
11 where object_name = 'NUFFIN';
12
13 x := x / y;
14
15 select rownum
16 into x
17 from dual;
18
19 exception
20 when others then
21 log_error;
22 raise;
23 end;
24 /
10. SQL> exec P;
BEGIN P; END;
*
ERROR at line 1:
ORA-01476: divisor is equal to zero
ORA-06512: at "SCOTT.P", line 22
11. SQL> create or replace procedure P is
2 x int;
3 y int;
4 begin
5
6 x := 10;
7
8 select count(*)
9 into y
10 from all_objects
11 where object_name = 'NUFFIN';
12
13 x := x / y;
14
15 select rownum
16 into x
17 from dual;
18
19 exception
20 when others then
21 log_error;
22 raise;
23 end;
24 /
?
12. SQL> create or replace procedure P is
2 x int;
3 y int;
4 begin
5
6 x := 10;
7
8 select count(*)
9 into y
10 from all_objects
11 where object_name = 'NUFFIN';
12
13 x := x / y;
14
15 select rownum
16 into x
17 from dual;
18
19 exception
20 when others then
21 dbms_output.put_line(
22 dbms_utility.format_call_stack);
23 raise;
24 end;
25 /
13. SQL> exec P;
----- PL/SQL Call Stack -----
object line object
handle number name
0x14b1e3900 21 procedure SCOTT.P
0x12521b8d8 1 anonymous block
BEGIN P; END;
*
ERROR at line 1:
ORA-01476: divisor is equal to zero
ORA-06512: at "SCOTT.P", line 23
ORA-06512: at line 1
14. SQL> create or replace procedure P is
2 x int;
3 y int;
4 l_debug varchar2(4000);
5 begin
6 l_debug := dbms_utility.format_call_stack;
7
8 x := 10;
9
10 l_debug := dbms_utility.format_call_stack;
11 select count(*)
12 into y
13 from all_objects
14 where object_name = 'NUFFIN';
15
16 l_debug := dbms_utility.format_call_stack;
17 x := x / y;
18
19 l_debug := dbms_utility.format_call_stack;
20 select rownum
21 into x
22 from dual;
23
24 exception
25 when others then
26 dbms_output.put_line(l_debug);
27 raise;
28 end;
15. SQL> exec P;
----- PL/SQL Call Stack -----
object line object
handle number name
0x14b1e3900 16 procedure SCOTT.P
0x12521b8d8 1 anonymous block
BEGIN P; END;
*
ERROR at line 1:
ORA-01476: divisor is equal to zero
ORA-06512: at "SCOTT.P", line 27
ORA-06512: at line 1
16. SQL> create or replace procedure P is
2 x int;
3 y int;
4 l_debug varchar2(4000);
5 begin
6 l_debug := dbms_utility.format_call_stack;
7
...
24 exception
25 when others then
26 l_debug := substr(l_debug,instr(l_debug,chr(10),1,3));
27 l_debug := regexp_replace(l_debug,chr(10)||'.*$');
28 dbms_output.put_line(l_debug);
29 raise;
30 end;
31 /
17. SQL> exec P;
0x14b1e3900 16 procedure SCOTT.P
BEGIN P; END;
*
ERROR at line 1:
ORA-01476: divisor is equal to zero
ORA-06512: at "SCOTT.P", line 29
ORA-06512: at line 1
20. SQL> create or replace procedure P is
2 x int;
3 y int;
4 l_debug varchar2(4000);
5 begin
6 l_debug := dbms_utility.format_call_stack;
7
8 x := 10;
9
...
23
24 exception
25 when others then
26 dbms_output.put_line(
27 DBMS_UTILITY.FORMAT_ERROR_BACKTRACE );
28 raise;
29 end;
21. SQL> exec P;
ORA-06512: at "SCOTT.P", line 17
BEGIN P; END;
*
ERROR at line 1:
ORA-01476: divisor is equal to zero
ORA-06512: at "SCOTT.P", line 27
ORA-06512: at line 1
25. SQL> create or replace procedure P is
2 x int;
3 y int;
4 begin
5 x := 10;
6
...
17
18 exception
19 when others then
20 for i in 1 .. utl_call_stack.dynamic_depth loop
21 dbms_output.put_line(
22 utl_call_stack.unit_line(i)||'-'||
23 utl_call_stack.concatenate_subprogram(
24 utl_call_stack.subprogram(i))
25 );
26 end loop;
27 raise;
28 end;
29. SQL> create or replace package body PKG is
2
3 procedure p is
...
19
20 exception
21 when others then
22 for i in 1 .. utl_call_stack.dynamic_depth loop
23 dbms_output.put_line(
24 utl_call_stack.unit_line(i)||'-'||
25 utl_call_stack.concatenate_subprogram(
26 utl_call_stack.subprogram(i))
27 );
28 end loop;
29 raise;
30 end;
31
32 procedure p1 is begin p; end;
33 procedure p2 is begin p1; end;
34 procedure p3 is begin p2; end;
35
36 end;
37 /
42. 42
SQL> select * from emp where empno = 7369;
no rows selected
SQL> select * from social_club where empno = 7369;
no rows selected
SQL> select * from footy_tipping where empno = 7369;
EMPNO ENAME TEAM
---------- ---------- ---------
7369 SMITH EAGLES
1 row selected.
48. 48
SQL> alter session set plsql_warnings = 'enable:all';
Session altered.
SQL> create or replace
2 procedure MY_PROC(ret_code out number) is
3 x number;
4 begin
5 x :=1 ;
6 ret_code := 0;
7 exception
8 when others then
9 ret_code := 1;
10 end;
11 /
SP2-0804: Procedure created with compilation warnings
LINE/COL ERROR
-------- -------------------------------------------------------
7/8 PLW-06009: procedure "MY_PROC" OTHERS handler does not
end in RAISE or RAISE_APPLICATION_ERROR
PLW-06009: YOU ARE A DUFUS !!!
49. 49
SQL> create or replace
2 procedure EMP_RESIGNED(p_empno number) is
3 begin
4 delete from EMP where empno = p_empno;
5
6 delete from SOCIAL_CLUB where empno = p_empno;
7
8 delete from FOOTY_TIPPING where empno = p_empno;
9
10 exception
11 when others then
12 -- notify_support_staff;
13 raise;
14 end;
15 /
Procedure created.
50. 50
SQL> exec EMP_RESIGNED(7369);
*
ERROR at line 1:
ORA-20000: Footy tipping table locked down during finals
ORA-06512: at "FINALS_FEVER", line 2
ORA-04088: error during execution of trigger 'FINALS_FEVER'
51. 51
SQL> select * from EMP where empno = 7369;
EMPNO ENAME JOB MGR HIREDATE SAL
---------- ---------- --------- ---------- --------- ----------
7369 SMITH CLERK 7902 17-DEC-80 800
1 row selected.
SQL> select * from SOCIAL_CLUB where empno = 7369;
EMPNO ENAME
---------- ----------
7369 SMITH
1 row selected.
SQL> select * from FOOTY_TIPPING where empno = 7369;
EMPNO ENAME TEAM
---------- ---------- ---------
7369 SMITH EAGLES
1 row selected.