SlideShare a Scribd company logo
1 of 51
1
12c
2
the focus ...
the day to day stuff
Feature
PL/SQL error handling
it all starts off easy
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.
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
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.
... and downhill from there
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 /
SQL> exec P;
BEGIN P; END;
*
ERROR at line 1:
ORA-01476: divisor is equal to zero
ORA-06512: at "SCOTT.P", line 22
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 /
?
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 /
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
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;
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
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 /
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
10g got better
DBMS_UTILITY.FORMAT_ERROR_BACKTRACE
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;
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
12c .... same rules apply but
structure
UTL_CALL_STACK
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;
SQL> exec P;
21-P
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
value in "real world"
SQL> create or replace package PKG is
2 procedure p;
3 procedure p1;
4 procedure p2;
5 procedure p3;
6 end;
7 /
Package created.
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 /
SQL> exec pkg.p3
23-PKG.P
32-PKG.P1
33-PKG.P2
34-PKG.P3
1-__anonymous_block
BEGIN pkg.p3; END;
*
ERROR at line 1:
ORA-01476: divisor is equal to
zero
ORA-06512: at "SCOTT.PKG", line 29
ORA-06512: at "SCOTT.PKG", line 32
ORA-06512: at "SCOTT.PKG", line 33
ORA-06512: at "SCOTT.PKG", line 34
ORA-06512: at line 1
did you miss it ?
SQL> exec pkg.p3
23-PKG.P
32-PKG.P1
33-PKG.P2
34-PKG.P3
1-__anonymous_block
BEGIN pkg.p3; END;
*
ERROR at line 1:
ORA-01476: divisor is equal to
zero
ORA-06512: at "SCOTT.PKG", line 29
ORA-06512: at "SCOTT.PKG", line 32
ORA-06512: at "SCOTT.PKG", line 33
ORA-06512: at "SCOTT.PKG", line 34
ORA-06512: at line 1
subprogram
quick segue: exceptions
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
...
27 raise;
28 end;
always raise (for OTHERS)
36
SQL> create or replace
2 procedure EMP_RESIGNED(p_empno number, ret_code out number) is
3 begin
4 delete from EMP
5 where empno = p_empno;
6
7 delete from SOCIAL_CLUB
8 where empno = p_empno;
9
10 delete from FOOTY_TIPPING
11 where empno = p_empno;
12
13 ret_code := 0;
14 exception
15 when others then
16
17 ret_code := 1;
18 end;
19 /
Procedure created.
log_error(sqlerrm);
37
{
CallableStatement cs = conn.prepareCall
("begin EMP_RESIGNED(?,?); end;");
cs.setString (1, 7369);
cs.registerOutParameter (2, Types.INTEGER);
cs.execute ();
int ret_code = cs.getInteger (1)
}
38
SQL> variable retcode number
SQL> begin
2 emp_resigned(7369,:retcode);
3 end;
4 /
PL/SQL procedure successfully completed.
SQL> print retcode
RETCODE
----------
1
39
corrupt your database
40
catching OTHERS exception
without re-raise
41
statetra ans ct oni
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.
43
"no problem"
44
SQL> create or replace
2 procedure EMP_RESIGNED(p_empno number, ret_code out number) is
3 begin
4 delete from EMP
5 where empno = p_empno;
6
7 delete from SOCIAL_CLUB
8 where empno = p_empno;
9
10 delete from FOOTY_TIPPING
11 where empno = p_empno;
12
13 ret_code := 0;
14 exception
15 when others then
16 ROLLBACK;
17 ret_code := 1;
18 end;
19 /
Procedure created.
45
corrupt your database
46
SQL> exec ADD_NEW_EMPLOYEE('SUSAN');
SQL> insert into EMAIL_SYSTEM
2 values ( … )
SQL> exec EMP_RESIGNED(1234,:retcode)
47
compiler warnings can help
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
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
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
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.

More Related Content

What's hot

Javascript basics
Javascript basicsJavascript basics
Javascript basicsFin Chen
 
Java, Up to Date Sources
Java, Up to Date SourcesJava, Up to Date Sources
Java, Up to Date Sources輝 子安
 
The Ring programming language version 1.10 book - Part 17 of 212
The Ring programming language version 1.10 book - Part 17 of 212The Ring programming language version 1.10 book - Part 17 of 212
The Ring programming language version 1.10 book - Part 17 of 212Mahmoud Samir Fayed
 
Connor McDonald 11g for developers
Connor McDonald 11g for developersConnor McDonald 11g for developers
Connor McDonald 11g for developersInSync Conference
 
10 Typical Enterprise Java Problems
10 Typical Enterprise Java Problems10 Typical Enterprise Java Problems
10 Typical Enterprise Java ProblemsEberhard Wolff
 
10 Typical Problems in Enterprise Java Applications
10 Typical Problems in Enterprise Java Applications10 Typical Problems in Enterprise Java Applications
10 Typical Problems in Enterprise Java ApplicationsEberhard Wolff
 
TDD CrashCourse Part5: Testing Techniques
TDD CrashCourse Part5: Testing TechniquesTDD CrashCourse Part5: Testing Techniques
TDD CrashCourse Part5: Testing TechniquesDavid Rodenas
 
Sumsem2014 15 cp0399-13-jun-2015_rm01_programs
Sumsem2014 15 cp0399-13-jun-2015_rm01_programsSumsem2014 15 cp0399-13-jun-2015_rm01_programs
Sumsem2014 15 cp0399-13-jun-2015_rm01_programsAbhijit Borah
 
Digital Voltmeter displaying voltage level on a seven segment display and com...
Digital Voltmeter displaying voltage level on a seven segment display and com...Digital Voltmeter displaying voltage level on a seven segment display and com...
Digital Voltmeter displaying voltage level on a seven segment display and com...Karthik Rathinavel
 
Programming JVM Bytecode with Jitescript
Programming JVM Bytecode with JitescriptProgramming JVM Bytecode with Jitescript
Programming JVM Bytecode with JitescriptJoe Kutner
 
Random stability in systemVerilog and UVM based testbench
Random stability in systemVerilog and UVM based testbenchRandom stability in systemVerilog and UVM based testbench
Random stability in systemVerilog and UVM based testbenchKashyap Adodariya
 
VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEVISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEDarwin Durand
 
Антон Нонко, Классические строки в C++
Антон Нонко, Классические строки в C++Антон Нонко, Классические строки в C++
Антон Нонко, Классические строки в C++Sergey Platonov
 
Travel management
Travel managementTravel management
Travel management1Parimal2
 
Аварийный дамп – чёрный ящик упавшей JVM. Андрей Паньгин
Аварийный дамп – чёрный ящик упавшей JVM. Андрей ПаньгинАварийный дамп – чёрный ящик упавшей JVM. Андрей Паньгин
Аварийный дамп – чёрный ящик упавшей JVM. Андрей Паньгинodnoklassniki.ru
 
JavaScript Proven Practises
JavaScript Proven PractisesJavaScript Proven Practises
JavaScript Proven PractisesRobert MacLean
 
Towards Reusable Components With Aspects [ICSE 2008]
Towards Reusable Components With Aspects [ICSE 2008]Towards Reusable Components With Aspects [ICSE 2008]
Towards Reusable Components With Aspects [ICSE 2008]Kevin Hoffman
 

What's hot (20)

Javascript basics
Javascript basicsJavascript basics
Javascript basics
 
Java, Up to Date Sources
Java, Up to Date SourcesJava, Up to Date Sources
Java, Up to Date Sources
 
E:\Plp 2009 2\Plp 9
E:\Plp 2009 2\Plp 9E:\Plp 2009 2\Plp 9
E:\Plp 2009 2\Plp 9
 
The Ring programming language version 1.10 book - Part 17 of 212
The Ring programming language version 1.10 book - Part 17 of 212The Ring programming language version 1.10 book - Part 17 of 212
The Ring programming language version 1.10 book - Part 17 of 212
 
Connor McDonald 11g for developers
Connor McDonald 11g for developersConnor McDonald 11g for developers
Connor McDonald 11g for developers
 
Static and const members
Static and const membersStatic and const members
Static and const members
 
10 Typical Enterprise Java Problems
10 Typical Enterprise Java Problems10 Typical Enterprise Java Problems
10 Typical Enterprise Java Problems
 
10 Typical Problems in Enterprise Java Applications
10 Typical Problems in Enterprise Java Applications10 Typical Problems in Enterprise Java Applications
10 Typical Problems in Enterprise Java Applications
 
TDD CrashCourse Part5: Testing Techniques
TDD CrashCourse Part5: Testing TechniquesTDD CrashCourse Part5: Testing Techniques
TDD CrashCourse Part5: Testing Techniques
 
Sumsem2014 15 cp0399-13-jun-2015_rm01_programs
Sumsem2014 15 cp0399-13-jun-2015_rm01_programsSumsem2014 15 cp0399-13-jun-2015_rm01_programs
Sumsem2014 15 cp0399-13-jun-2015_rm01_programs
 
Digital Voltmeter displaying voltage level on a seven segment display and com...
Digital Voltmeter displaying voltage level on a seven segment display and com...Digital Voltmeter displaying voltage level on a seven segment display and com...
Digital Voltmeter displaying voltage level on a seven segment display and com...
 
Programming JVM Bytecode with Jitescript
Programming JVM Bytecode with JitescriptProgramming JVM Bytecode with Jitescript
Programming JVM Bytecode with Jitescript
 
Random stability in systemVerilog and UVM based testbench
Random stability in systemVerilog and UVM based testbenchRandom stability in systemVerilog and UVM based testbench
Random stability in systemVerilog and UVM based testbench
 
VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEVISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLE
 
Антон Нонко, Классические строки в C++
Антон Нонко, Классические строки в C++Антон Нонко, Классические строки в C++
Антон Нонко, Классические строки в C++
 
Travel management
Travel managementTravel management
Travel management
 
.net progrmming part1
.net progrmming part1.net progrmming part1
.net progrmming part1
 
Аварийный дамп – чёрный ящик упавшей JVM. Андрей Паньгин
Аварийный дамп – чёрный ящик упавшей JVM. Андрей ПаньгинАварийный дамп – чёрный ящик упавшей JVM. Андрей Паньгин
Аварийный дамп – чёрный ящик упавшей JVM. Андрей Паньгин
 
JavaScript Proven Practises
JavaScript Proven PractisesJavaScript Proven Practises
JavaScript Proven Practises
 
Towards Reusable Components With Aspects [ICSE 2008]
Towards Reusable Components With Aspects [ICSE 2008]Towards Reusable Components With Aspects [ICSE 2008]
Towards Reusable Components With Aspects [ICSE 2008]
 

Similar to 12c Mini Lesson - Improved Error Handling in PLSQL

UKOUG - 25 years of hints and tips
UKOUG - 25 years of hints and tipsUKOUG - 25 years of hints and tips
UKOUG - 25 years of hints and tipsConnor McDonald
 
A New View of Database Views
A New View of Database ViewsA New View of Database Views
A New View of Database ViewsMichael Rosenblum
 
PostgreSQL Procedural Languages: Tips, Tricks and Gotchas
PostgreSQL Procedural Languages: Tips, Tricks and GotchasPostgreSQL Procedural Languages: Tips, Tricks and Gotchas
PostgreSQL Procedural Languages: Tips, Tricks and GotchasJim Mlodgenski
 
OpenWorld Sep14 12c for_developers
OpenWorld Sep14 12c for_developersOpenWorld Sep14 12c for_developers
OpenWorld Sep14 12c for_developersConnor McDonald
 
Database Management System
Database Management SystemDatabase Management System
Database Management SystemHitesh Mohapatra
 
Digital System Design-Synchronous Sequential Circuits
Digital System Design-Synchronous Sequential CircuitsDigital System Design-Synchronous Sequential Circuits
Digital System Design-Synchronous Sequential CircuitsIndira Priyadarshini
 
11 Things About 11gr2
11 Things About 11gr211 Things About 11gr2
11 Things About 11gr2afa reg
 
Lecture#5 Operators in C++
Lecture#5 Operators in C++Lecture#5 Operators in C++
Lecture#5 Operators in C++NUST Stuff
 
Latin America Tour 2019 - 10 great sql features
Latin America Tour 2019  - 10 great sql featuresLatin America Tour 2019  - 10 great sql features
Latin America Tour 2019 - 10 great sql featuresConnor McDonald
 
Runtime Code Generation and Data Management for Heterogeneous Computing in Java
Runtime Code Generation and Data Management for Heterogeneous Computing in JavaRuntime Code Generation and Data Management for Heterogeneous Computing in Java
Runtime Code Generation and Data Management for Heterogeneous Computing in JavaJuan Fumero
 
Profiling of Oracle Function Calls
Profiling of Oracle Function CallsProfiling of Oracle Function Calls
Profiling of Oracle Function CallsEnkitec
 
12c Mini Lesson - Better Defaults
12c Mini Lesson - Better Defaults12c Mini Lesson - Better Defaults
12c Mini Lesson - Better DefaultsConnor McDonald
 

Similar to 12c Mini Lesson - Improved Error Handling in PLSQL (20)

PLSQL.docx
PLSQL.docxPLSQL.docx
PLSQL.docx
 
UKOUG - 25 years of hints and tips
UKOUG - 25 years of hints and tipsUKOUG - 25 years of hints and tips
UKOUG - 25 years of hints and tips
 
A New View of Database Views
A New View of Database ViewsA New View of Database Views
A New View of Database Views
 
Plsql programs
Plsql programsPlsql programs
Plsql programs
 
PL/SQL
PL/SQLPL/SQL
PL/SQL
 
PostgreSQL Procedural Languages: Tips, Tricks and Gotchas
PostgreSQL Procedural Languages: Tips, Tricks and GotchasPostgreSQL Procedural Languages: Tips, Tricks and Gotchas
PostgreSQL Procedural Languages: Tips, Tricks and Gotchas
 
February0504 pm
February0504 pmFebruary0504 pm
February0504 pm
 
Loops
LoopsLoops
Loops
 
OpenWorld Sep14 12c for_developers
OpenWorld Sep14 12c for_developersOpenWorld Sep14 12c for_developers
OpenWorld Sep14 12c for_developers
 
Database Management System
Database Management SystemDatabase Management System
Database Management System
 
PL-SQL.pdf
PL-SQL.pdfPL-SQL.pdf
PL-SQL.pdf
 
Digital System Design-Synchronous Sequential Circuits
Digital System Design-Synchronous Sequential CircuitsDigital System Design-Synchronous Sequential Circuits
Digital System Design-Synchronous Sequential Circuits
 
11 Things About 11gr2
11 Things About 11gr211 Things About 11gr2
11 Things About 11gr2
 
Verilog_Examples (1).pdf
Verilog_Examples (1).pdfVerilog_Examples (1).pdf
Verilog_Examples (1).pdf
 
Lecture#5 Operators in C++
Lecture#5 Operators in C++Lecture#5 Operators in C++
Lecture#5 Operators in C++
 
Latin America Tour 2019 - 10 great sql features
Latin America Tour 2019  - 10 great sql featuresLatin America Tour 2019  - 10 great sql features
Latin America Tour 2019 - 10 great sql features
 
Runtime Code Generation and Data Management for Heterogeneous Computing in Java
Runtime Code Generation and Data Management for Heterogeneous Computing in JavaRuntime Code Generation and Data Management for Heterogeneous Computing in Java
Runtime Code Generation and Data Management for Heterogeneous Computing in Java
 
Profiling of Oracle Function Calls
Profiling of Oracle Function CallsProfiling of Oracle Function Calls
Profiling of Oracle Function Calls
 
VLSI lab manual
VLSI lab manualVLSI lab manual
VLSI lab manual
 
12c Mini Lesson - Better Defaults
12c Mini Lesson - Better Defaults12c Mini Lesson - Better Defaults
12c Mini Lesson - Better Defaults
 

More from Connor McDonald

Sangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolestSangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolestConnor McDonald
 
Sangam 19 - Analytic SQL
Sangam 19 - Analytic SQLSangam 19 - Analytic SQL
Sangam 19 - Analytic SQLConnor McDonald
 
Sangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on AutonomousSangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on AutonomousConnor McDonald
 
Sangam 2019 - The Latest Features
Sangam 2019 - The Latest FeaturesSangam 2019 - The Latest Features
Sangam 2019 - The Latest FeaturesConnor McDonald
 
UKOUG 2019 - SQL features
UKOUG 2019 - SQL featuresUKOUG 2019 - SQL features
UKOUG 2019 - SQL featuresConnor McDonald
 
APEX tour 2019 - successful development with autonomous
APEX tour 2019 - successful development with autonomousAPEX tour 2019 - successful development with autonomous
APEX tour 2019 - successful development with autonomousConnor McDonald
 
APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne Connor McDonald
 
OOW19 - Flashback, not just for DBAs
OOW19 - Flashback, not just for DBAsOOW19 - Flashback, not just for DBAs
OOW19 - Flashback, not just for DBAsConnor McDonald
 
OOW19 - Read consistency
OOW19 - Read consistencyOOW19 - Read consistency
OOW19 - Read consistencyConnor McDonald
 
OOW19 - Slower and less secure applications
OOW19 - Slower and less secure applicationsOOW19 - Slower and less secure applications
OOW19 - Slower and less secure applicationsConnor McDonald
 
OOW19 - Killing database sessions
OOW19 - Killing database sessionsOOW19 - Killing database sessions
OOW19 - Killing database sessionsConnor McDonald
 
OOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL featuresOOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL featuresConnor McDonald
 
Latin America Tour 2019 - 18c and 19c featues
Latin America Tour 2019   - 18c and 19c featuesLatin America Tour 2019   - 18c and 19c featues
Latin America Tour 2019 - 18c and 19c featuesConnor McDonald
 
Latin America tour 2019 - Flashback
Latin America tour 2019 -  FlashbackLatin America tour 2019 -  Flashback
Latin America tour 2019 - FlashbackConnor McDonald
 
Latin America Tour 2019 - pattern matching
Latin America Tour 2019 - pattern matchingLatin America Tour 2019 - pattern matching
Latin America Tour 2019 - pattern matchingConnor McDonald
 
Latin America Tour 2019 - slow data and sql processing
Latin America Tour 2019  - slow data and sql processingLatin America Tour 2019  - slow data and sql processing
Latin America Tour 2019 - slow data and sql processingConnor McDonald
 
OG Yatra - upgrading to the new 12c+ optimizer
OG Yatra - upgrading to the new 12c+ optimizerOG Yatra - upgrading to the new 12c+ optimizer
OG Yatra - upgrading to the new 12c+ optimizerConnor McDonald
 
OG Yatra - 25 years of hints and tips
OG Yatra - 25 years of hints and tipsOG Yatra - 25 years of hints and tips
OG Yatra - 25 years of hints and tipsConnor McDonald
 

More from Connor McDonald (20)

Flashback ITOUG
Flashback ITOUGFlashback ITOUG
Flashback ITOUG
 
Sangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolestSangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolest
 
Sangam 19 - Analytic SQL
Sangam 19 - Analytic SQLSangam 19 - Analytic SQL
Sangam 19 - Analytic SQL
 
Sangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on AutonomousSangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on Autonomous
 
Sangam 2019 - The Latest Features
Sangam 2019 - The Latest FeaturesSangam 2019 - The Latest Features
Sangam 2019 - The Latest Features
 
UKOUG 2019 - SQL features
UKOUG 2019 - SQL featuresUKOUG 2019 - SQL features
UKOUG 2019 - SQL features
 
APEX tour 2019 - successful development with autonomous
APEX tour 2019 - successful development with autonomousAPEX tour 2019 - successful development with autonomous
APEX tour 2019 - successful development with autonomous
 
APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne
 
OOW19 - Flashback, not just for DBAs
OOW19 - Flashback, not just for DBAsOOW19 - Flashback, not just for DBAs
OOW19 - Flashback, not just for DBAs
 
OOW19 - Read consistency
OOW19 - Read consistencyOOW19 - Read consistency
OOW19 - Read consistency
 
OOW19 - Slower and less secure applications
OOW19 - Slower and less secure applicationsOOW19 - Slower and less secure applications
OOW19 - Slower and less secure applications
 
OOW19 - Killing database sessions
OOW19 - Killing database sessionsOOW19 - Killing database sessions
OOW19 - Killing database sessions
 
OOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL featuresOOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL features
 
Latin America Tour 2019 - 18c and 19c featues
Latin America Tour 2019   - 18c and 19c featuesLatin America Tour 2019   - 18c and 19c featues
Latin America Tour 2019 - 18c and 19c featues
 
Latin America tour 2019 - Flashback
Latin America tour 2019 -  FlashbackLatin America tour 2019 -  Flashback
Latin America tour 2019 - Flashback
 
Latin America Tour 2019 - pattern matching
Latin America Tour 2019 - pattern matchingLatin America Tour 2019 - pattern matching
Latin America Tour 2019 - pattern matching
 
Latin America Tour 2019 - slow data and sql processing
Latin America Tour 2019  - slow data and sql processingLatin America Tour 2019  - slow data and sql processing
Latin America Tour 2019 - slow data and sql processing
 
ANSI vs Oracle language
ANSI vs Oracle languageANSI vs Oracle language
ANSI vs Oracle language
 
OG Yatra - upgrading to the new 12c+ optimizer
OG Yatra - upgrading to the new 12c+ optimizerOG Yatra - upgrading to the new 12c+ optimizer
OG Yatra - upgrading to the new 12c+ optimizer
 
OG Yatra - 25 years of hints and tips
OG Yatra - 25 years of hints and tipsOG Yatra - 25 years of hints and tips
OG Yatra - 25 years of hints and tips
 

Recently uploaded

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 

Recently uploaded (20)

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 

12c Mini Lesson - Improved Error Handling in PLSQL

  • 2. 2 the focus ... the day to day stuff
  • 4. it all starts off easy
  • 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.
  • 8. ... and downhill from there
  • 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
  • 22. 12c .... same rules apply but
  • 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;
  • 26. SQL> exec P; 21-P 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
  • 27. value in "real world"
  • 28. SQL> create or replace package PKG is 2 procedure p; 3 procedure p1; 4 procedure p2; 5 procedure p3; 6 end; 7 / Package created.
  • 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 /
  • 30. SQL> exec pkg.p3 23-PKG.P 32-PKG.P1 33-PKG.P2 34-PKG.P3 1-__anonymous_block BEGIN pkg.p3; END; * ERROR at line 1: ORA-01476: divisor is equal to zero ORA-06512: at "SCOTT.PKG", line 29 ORA-06512: at "SCOTT.PKG", line 32 ORA-06512: at "SCOTT.PKG", line 33 ORA-06512: at "SCOTT.PKG", line 34 ORA-06512: at line 1
  • 31. did you miss it ?
  • 32. SQL> exec pkg.p3 23-PKG.P 32-PKG.P1 33-PKG.P2 34-PKG.P3 1-__anonymous_block BEGIN pkg.p3; END; * ERROR at line 1: ORA-01476: divisor is equal to zero ORA-06512: at "SCOTT.PKG", line 29 ORA-06512: at "SCOTT.PKG", line 32 ORA-06512: at "SCOTT.PKG", line 33 ORA-06512: at "SCOTT.PKG", line 34 ORA-06512: at line 1 subprogram
  • 34. 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 ... 27 raise; 28 end;
  • 35. always raise (for OTHERS)
  • 36. 36 SQL> create or replace 2 procedure EMP_RESIGNED(p_empno number, ret_code out number) is 3 begin 4 delete from EMP 5 where empno = p_empno; 6 7 delete from SOCIAL_CLUB 8 where empno = p_empno; 9 10 delete from FOOTY_TIPPING 11 where empno = p_empno; 12 13 ret_code := 0; 14 exception 15 when others then 16 17 ret_code := 1; 18 end; 19 / Procedure created. log_error(sqlerrm);
  • 37. 37 { CallableStatement cs = conn.prepareCall ("begin EMP_RESIGNED(?,?); end;"); cs.setString (1, 7369); cs.registerOutParameter (2, Types.INTEGER); cs.execute (); int ret_code = cs.getInteger (1) }
  • 38. 38 SQL> variable retcode number SQL> begin 2 emp_resigned(7369,:retcode); 3 end; 4 / PL/SQL procedure successfully completed. SQL> print retcode RETCODE ---------- 1
  • 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.
  • 44. 44 SQL> create or replace 2 procedure EMP_RESIGNED(p_empno number, ret_code out number) is 3 begin 4 delete from EMP 5 where empno = p_empno; 6 7 delete from SOCIAL_CLUB 8 where empno = p_empno; 9 10 delete from FOOTY_TIPPING 11 where empno = p_empno; 12 13 ret_code := 0; 14 exception 15 when others then 16 ROLLBACK; 17 ret_code := 1; 18 end; 19 / Procedure created.
  • 46. 46 SQL> exec ADD_NEW_EMPLOYEE('SUSAN'); SQL> insert into EMAIL_SYSTEM 2 values ( … ) SQL> exec EMP_RESIGNED(1234,:retcode)
  • 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.