SlideShare a Scribd company logo
Weird PL/SQL Steven Feuerstein PL/SQL Evangelist, Quest Software www.quest.com  steven.feuerstein@quest.com
How to benefit most from this session Watch, listen,  ask questions . Then afterwards.... Download and use any of my the training materials, available at my "cyber home" on Toad World, a portal for Toad Users and PL/SQL developers: You have my permission to use  all  these materials to do internal trainings and build your own applications. But they should not considered production ready. You must test them and modify them to fit your needs. filename_from_demo_zip.sql Download and use any of my scripts (examples, performance scripts, reusable code) from the demo.zip, available from the same place. http://www.ToadWorld.com/SF PL/SQL Obsession
I Love PL/SQL And... We all love PL/SQL. But we all know there are ways in which it could be improved. And I will be pointing to lots of such ways in this seminar. I created ILovePLSQLAnd.net to make it easy for PL/SQL users to influence the future direction of the language. Please use it! http://www.ILovePLSQLAnd.net
The agenda  C'mon, PL/SQL is  not  weird. SQLERRM and DBMS_OUTPUT.PUT_LINE Error codes: positive, negative, either, both? The built-in string parsing program - NOT! VARCHAR2 memory allocation VARRAY - what kind of varrying is that? $IF I understood $IF I would be amazing! The mystery of "reserved words" in PL/SQL Where's my line number? Where's my program name? Zero length strings and NULL %ROWTYPE and %TYPE
C'mon, PL/SQL is  not  WEIRD! That's true. It really isn't a weird language.  Anybody ever use LISP? In fact, it is a very readable, accessible and enjoyable language. It is also a very robust and powerful language. All thanks to the PL/SQL dev team! So when I make fun of certain aspects of PL/SQL, I do it out of the deepest respect and appreciation - and desire to make PL/SQL even better! Thank you, PL/SQL Dev Team!
PL/SQL - the  Really  Readable Language Let's compare Java and PL/SQL.... public class  Hello  { public static void  main  ( String  []  args ) { System . out . println  ( "Hello World!" ); } } CREATE OR  REPLACE  PROCEDURE hello  ( IS BEGIN DBMS_OUTPUT.PUT_LINE  ('Hello world!'); END hello ; PL/SQL isn't as powerful as Java, but it's  much  easier to write - and understand!
SQLERRM and DBMS_OUTPUT.PUT_LINE SQLERRM returns the error text for the specified error code. If none is provided, then SQLCODE is assumed. But SQLERRM might  truncate your error message! Currently at 512, earlier at 255. 255...255...what does that number remind us of! Ah, yes: DBMS_OUTPUT.PUT_LINE So use DBMS_UTILITY.FORMAT_ERROR_STACK instead! sqlerrm.sql
Error codes: positive, negative, either, both? We all know that Oracle errors are negative. Well, except for 1 and 100. Hey, that NO_DATA_FOUND is pretty strange all by itself! Oh, and error codes saved by SAVE EXCEPTIONS. And error codes saved by DBMS_ERRLOG At least the EXCEPTION_INIT pragma has it straight - more or less. STANDARD package in RDBMS\Admin: stdspec.sql stdbody.sql bulkexc.sql  dbms_errlog*.*  exception_init.sql
More on errors: the price of laziness -    or is it cost-cutting? It's as if someone at Oracle calculated that declaring new exceptions cost $74 each. Larry: "Save $1B in costs this year!" Developers: "OK, we won't declare new exceptions." And so we have "recycled" exceptions: NO_DATA_FOUND: pure confusion VALUE_ERROR: sub-message text excquiz6*.sql value_error_demo.sql
The built-in string parsing program - NOT! Surely any robust programming language provides a program to parse a delimited string. And PL/SQL is no exception.... Well, sort of. Oracle gave us: DBMS_UTILITY.COMMA_TO_TABLE String cannot be NULL - raises error! Only parses comma-delimited strings. Every element in the list must be a  valid PL/SQL identifier. You can't make this stuff up! commatotable.tst sqlerrm.sql
Parsing programs to the rescue Well, the main thing is that  you  should not have to write these algorithms over and over yourself. So here are some options: parse.pkg - parse any delimited string, returns a collection of type defined in package. str2list.pkg - parse any delimited string, returns a collection based  on your own type . Regular expressions parse.pkg str2list.pkg str2list2.pkg
VARCHAR2 memory allocation Memory for VARCHAR2 variables is only allocated as needed, right? Variable-length  strings! OK, then which of the following variables consume the most memory? DECLARE l_var1  VARCHAR2 (32767); l_var2  VARCHAR2 (4050); l_var3  VARCHAR2 (500); BEGIN l_var1 := 'a'; l_var2 := 'a'; l_var3 := 'a'; END; / That's right! l_var3
VARRAY - what kind of varrying is that? Oracle offers three kinds of collections Associative Array Nested table Varray, a.k.a, "Varrying array" That's weird enough, all by itself, really. But what I find truly odd is the use of the name "varrying array". It is the  least varrying  of all the different types of collections! associative_array_example.sql nested_table_example.sql varray_example.sql collection_of_records.sql
$IF I understood $IF I would be amazing! Have you ever used the $ syntax added to PL/SQL in Oracle10g Release 2? It looks  very weird . But it is  very useful . With conditional compilation, you can.... Write code that will compile and run under different versions of Oracle (relevant for future releases).  Run different code for test, debug and production phases. That is, compile debug statements in and out of your code. Expose private modules for unit testing. cc_version_check.sql cc_debug_trace.sql 11g_emplu.pkg
The mystery of "reserved words" in PL/SQL What will happen when I run this code? DECLARE PLS_INTEGER  VARCHAR2 (1); NO_DATA_FOUND  EXCEPTION; BEGIN SELECT dummy INTO PLS_INTEGER FROM DUAL WHERE 1 = 2; IF PLS_INTEGER IS NULL THEN RAISE NO_DATA_FOUND; END IF; EXCEPTION WHEN NO_DATA_FOUND THEN DBMS_OUTPUT.put_line ('No dummy!'); END; excquiz5.sql
Exploring the STANDARD package Much of what we consider to be the base PL/SQL language is defined in the STANDARD package. One of two "default" packages; the other is DBMS_STANDARD. You can view the contents of the STANDARD package (and other "supplied" packages by visiting the appropriate variation of: $ORACLE_HOME/Rdbms/Admin
Where's my line number? An exception is raised. I trap it and log the error. I want to see the line number on which the error is raised. If I am not yet on Oracle 10g Release 2,  I am  totally out of luck. Keep up with Oracle, though, and then you can take advantage of  DBMS_UTILITY.FORMAT_ERROR_BACKTRACE Call it  every time  you log an error! Backtrace.sql Quest Error Manager - www.ToadWorld.com - Downloads
Where's my program name? DBMS_UTILITY.FORMAT_CALL_STACK answers the question: "How did I get here?" DBMS_UTILITY.FORMAT_ERROR_BACKTRACE  answers the question: "Where did my error come from?" But in both cases....if the program in question is located inside a package, I don't see the name of that subprogram. Please, Oracle, give me my program name!  Heck, and my overloading, while you are at it.
Zero length strings and NULL A NULL string and a zero length string  ( '' ) are supposed to be treated the same way inside Oracle. And for the most part it is true. But when it comes to ORA-06502: PL/SQL: numeric or value error: NULL index table key value You can get some rather  weird  behavior! Especially on Oracle11g.... null_index_value.sql zero_length_string.sql
%TYPE  and  %ROWTYPE? I have enormous respect for the PL/SQL team.  Not only are they are all smarter than me, they are  real  computer scientists. I am an amateur by comparison. And their design of the PL/SQL syntax is for the most part very elegant and minimalist. But why do we have to have both %TYPE  and  %ROWTYPE?
So I hope you now agree with me... PL/SQL can be a little bit weird sometimes. But it is still a truly  elegant and straightforward  language. Those features make it, in turn,  accessible and productive . And that's why so many of us have achieved  personal success , and have implemented so many  successful applications  with the PL/SQL language.

More Related Content

What's hot (20)

PPTX
PHP
Steve Fort
 
PDF
Php tutorial(w3schools)
Arjun Shanka
 
PPT
Beginners PHP Tutorial
alexjones89
 
PDF
Api Design
sumithra jonnalagadda
 
ODP
YAPC::NA 2007 - An Introduction To Perl Critic
joshua.mcadams
 
ODP
Um2010
Jun Furuse
 
DOC
Php tutorial
S Bharadwaj
 
PDF
Introduction to PHP
Bradley Holt
 
PPTX
Php.ppt
Nidhi mishra
 
PPTX
PHP tutorial | ptutorial
PTutorial Web
 
PPTX
Php
Shyam Khant
 
PPTX
Clean Code
Nascenia IT
 
PPT
Laurens Van Den Oever Xopus Presentation
Ajax Experience 2009
 
PPS
Coding Best Practices
mh_azad
 
PPT
Introduction to PHP
Jussi Pohjolainen
 
ODP
An Introduction To Perl Critic
joshua.mcadams
 
PPTX
PHP 5.3
Chris Stone
 
PDF
Last train to php 7
Damien Seguy
 
PPT
Php(report)
Yhannah
 
Php tutorial(w3schools)
Arjun Shanka
 
Beginners PHP Tutorial
alexjones89
 
YAPC::NA 2007 - An Introduction To Perl Critic
joshua.mcadams
 
Um2010
Jun Furuse
 
Php tutorial
S Bharadwaj
 
Introduction to PHP
Bradley Holt
 
Php.ppt
Nidhi mishra
 
PHP tutorial | ptutorial
PTutorial Web
 
Clean Code
Nascenia IT
 
Laurens Van Den Oever Xopus Presentation
Ajax Experience 2009
 
Coding Best Practices
mh_azad
 
Introduction to PHP
Jussi Pohjolainen
 
An Introduction To Perl Critic
joshua.mcadams
 
PHP 5.3
Chris Stone
 
Last train to php 7
Damien Seguy
 
Php(report)
Yhannah
 

Viewers also liked (18)

PPTX
Oracle SQL Developer version 4.0 New Features Overview
Jeff Smith
 
PPTX
OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 2
Marco Gralike
 
PPTX
Turbocharge SQL Performance in PL/SQL with Bulk Processing
Steven Feuerstein
 
PDF
Printing with APEX: PL/PDF
Enkitec
 
PPTX
The Amazing and Elegant PL/SQL Function Result Cache
Steven Feuerstein
 
PPTX
utPLSQL: Unit Testing for Oracle PL/SQL
Steven Feuerstein
 
PPTX
Oracle PL/SQL Best Practices
Emrah METE
 
PPSX
Oracle database 12c new features
Remote DBA Services
 
PDF
Using Angular JS in APEX
Enkitec
 
PPTX
Introducing Node.js in an Oracle technology environment (including hands-on)
Lucas Jellema
 
PDF
Secure Architecture and Programming 101
QAware GmbH
 
PDF
Oracle sql & plsql
Sid Xing
 
PPTX
Oracle SQL Developer Tips & Tricks
Jeff Smith
 
PPTX
Oracle database 12c new features
Jakkrapat S.
 
PPTX
Oracle Basics and Architecture
Sidney Chen
 
ODP
Introduction to Oracle Financials
hasan2000
 
ODP
Open Gurukul Language PL/SQL
Open Gurukul
 
PPS
Oracle Database Overview
honglee71
 
Oracle SQL Developer version 4.0 New Features Overview
Jeff Smith
 
OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 2
Marco Gralike
 
Turbocharge SQL Performance in PL/SQL with Bulk Processing
Steven Feuerstein
 
Printing with APEX: PL/PDF
Enkitec
 
The Amazing and Elegant PL/SQL Function Result Cache
Steven Feuerstein
 
utPLSQL: Unit Testing for Oracle PL/SQL
Steven Feuerstein
 
Oracle PL/SQL Best Practices
Emrah METE
 
Oracle database 12c new features
Remote DBA Services
 
Using Angular JS in APEX
Enkitec
 
Introducing Node.js in an Oracle technology environment (including hands-on)
Lucas Jellema
 
Secure Architecture and Programming 101
QAware GmbH
 
Oracle sql & plsql
Sid Xing
 
Oracle SQL Developer Tips & Tricks
Jeff Smith
 
Oracle database 12c new features
Jakkrapat S.
 
Oracle Basics and Architecture
Sidney Chen
 
Introduction to Oracle Financials
hasan2000
 
Open Gurukul Language PL/SQL
Open Gurukul
 
Oracle Database Overview
honglee71
 
Ad

Similar to Weird Plsql (20)

PPTX
PLSQLmy Updated (1).pptx
vamsiyadav39
 
PDF
Unit 4 rdbms study_material
gayaramesh
 
PPTX
Ch as pbdasdadssadsadsadasdasdasdas fdt .pptx
sharmilasatishpore
 
PDF
PL/SQL Complete Tutorial. All Topics Covered
Danish Mehraj
 
PPTX
pl/sql online Training|sql online Training | iTeknowledge
Masood Khan
 
PDF
rdbms.pdf plsql database system notes for students to study
rarelyused
 
PPTX
Pl sql Prograaming of Database management system
AjitPatil801582
 
PDF
Pl sql
chaitanyanaredla
 
PDF
Pl sql
Priya Laxmanan
 
PPTX
Unit 4 plsql
DrkhanchanaR
 
PDF
Database & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdf
InSync2011
 
PDF
2 Fundamentals of the PL_SQL Language.pdf
sheriframadan18
 
PDF
RDBMS - UNIT 4.pdf,UNIT THREE AND UNIT FIVE
ajitharaja2003
 
PPT
10g plsql slide
Tanu_Manu
 
DOC
3963066 pl-sql-notes-only
Ashwin Kumar
 
PDF
PLSQL Note
Arun Sial
 
PPTX
PL SQL.pptx in computer language in database
ironman82715
 
PPTX
4. plsql
Amrit Kaur
 
PDF
Database management system chapter5
Pranab Dasgupta
 
PLSQLmy Updated (1).pptx
vamsiyadav39
 
Unit 4 rdbms study_material
gayaramesh
 
Ch as pbdasdadssadsadsadasdasdasdas fdt .pptx
sharmilasatishpore
 
PL/SQL Complete Tutorial. All Topics Covered
Danish Mehraj
 
pl/sql online Training|sql online Training | iTeknowledge
Masood Khan
 
rdbms.pdf plsql database system notes for students to study
rarelyused
 
Pl sql Prograaming of Database management system
AjitPatil801582
 
Unit 4 plsql
DrkhanchanaR
 
Database & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdf
InSync2011
 
2 Fundamentals of the PL_SQL Language.pdf
sheriframadan18
 
RDBMS - UNIT 4.pdf,UNIT THREE AND UNIT FIVE
ajitharaja2003
 
10g plsql slide
Tanu_Manu
 
3963066 pl-sql-notes-only
Ashwin Kumar
 
PLSQL Note
Arun Sial
 
PL SQL.pptx in computer language in database
ironman82715
 
4. plsql
Amrit Kaur
 
Database management system chapter5
Pranab Dasgupta
 
Ad

Recently uploaded (20)

PPTX
_IIML_Optimizing Energy Efficiency in Industrial Operations with GenAI_Team I...
rafinrowshan
 
PDF
NewBase 07 July 2025 Energy News issue - 1800 by Khaled Al Awadi_compressed.pdf
Khaled Al Awadi
 
PPTX
6 Critical Factors to Evaluate Before Starting a Retail Business
RUPAL AGARWAL
 
PDF
Top Farewell Gifts for Seniors Under.pdf
ThreadVibe Living
 
PDF
Buy Verified Payoneer Account – 100% Best With All Documents.pdf
buypaypalaccountsee buypaypalaccounts
 
PDF
LEWIONICS SCO Company Profile UAE JULY 2025
Natalie Lewes
 
PDF
Blind Spots in Business: Unearthing Hidden Challenges in Today's Organizations
Crimson Business Consulting
 
PDF
How to Make Your Pre Seed Startup Grant Fundable
ideatoipo
 
PDF
Patrick Dwyer Merrill Lynch - A Governing Board Director
Patrick Dwyer Merrill Lynch
 
PDF
Concept Topology in Architectural Build Addendum.pdf
Brij Consulting, LLC
 
PDF
Thane Stenner - An Industry Expert
Thane Stenner
 
PDF
Buy Boys Long Sleeve T-shirts at Port 213
Port 213
 
PDF
Redefining Punjab’s Growth Story_ Mohit Bansal and the Human-Centric Vision o...
Mohit Bansal GMI
 
PPTX
epi editorial commitee meeting presentation
MIPLM
 
PDF
Azumah Resources reaffirms commitment to Ghana amid dispute with Engineers & ...
Kweku Zurek
 
PPTX
How Essar Transforms the Planet while Investing in People Over Profit
essarcase
 
PPTX
2025 July - ABM for B2B in Hubspot - Demand Gen HUG.pptx
mjenkins13
 
PDF
SUMMER SAFETY FLYER SPECIAL Q3 - 16 Pages
One Source Industrial Supplies
 
PDF
David Badaro Explains 5 Steps to Solving Complex Business Issues
David Badaro
 
PDF
LeadershipHQ Overview Flyer 2025-2026 Global
Sonia McDonald
 
_IIML_Optimizing Energy Efficiency in Industrial Operations with GenAI_Team I...
rafinrowshan
 
NewBase 07 July 2025 Energy News issue - 1800 by Khaled Al Awadi_compressed.pdf
Khaled Al Awadi
 
6 Critical Factors to Evaluate Before Starting a Retail Business
RUPAL AGARWAL
 
Top Farewell Gifts for Seniors Under.pdf
ThreadVibe Living
 
Buy Verified Payoneer Account – 100% Best With All Documents.pdf
buypaypalaccountsee buypaypalaccounts
 
LEWIONICS SCO Company Profile UAE JULY 2025
Natalie Lewes
 
Blind Spots in Business: Unearthing Hidden Challenges in Today's Organizations
Crimson Business Consulting
 
How to Make Your Pre Seed Startup Grant Fundable
ideatoipo
 
Patrick Dwyer Merrill Lynch - A Governing Board Director
Patrick Dwyer Merrill Lynch
 
Concept Topology in Architectural Build Addendum.pdf
Brij Consulting, LLC
 
Thane Stenner - An Industry Expert
Thane Stenner
 
Buy Boys Long Sleeve T-shirts at Port 213
Port 213
 
Redefining Punjab’s Growth Story_ Mohit Bansal and the Human-Centric Vision o...
Mohit Bansal GMI
 
epi editorial commitee meeting presentation
MIPLM
 
Azumah Resources reaffirms commitment to Ghana amid dispute with Engineers & ...
Kweku Zurek
 
How Essar Transforms the Planet while Investing in People Over Profit
essarcase
 
2025 July - ABM for B2B in Hubspot - Demand Gen HUG.pptx
mjenkins13
 
SUMMER SAFETY FLYER SPECIAL Q3 - 16 Pages
One Source Industrial Supplies
 
David Badaro Explains 5 Steps to Solving Complex Business Issues
David Badaro
 
LeadershipHQ Overview Flyer 2025-2026 Global
Sonia McDonald
 

Weird Plsql

  • 1. Weird PL/SQL Steven Feuerstein PL/SQL Evangelist, Quest Software www.quest.com [email protected]
  • 2. How to benefit most from this session Watch, listen, ask questions . Then afterwards.... Download and use any of my the training materials, available at my "cyber home" on Toad World, a portal for Toad Users and PL/SQL developers: You have my permission to use all these materials to do internal trainings and build your own applications. But they should not considered production ready. You must test them and modify them to fit your needs. filename_from_demo_zip.sql Download and use any of my scripts (examples, performance scripts, reusable code) from the demo.zip, available from the same place. http://www.ToadWorld.com/SF PL/SQL Obsession
  • 3. I Love PL/SQL And... We all love PL/SQL. But we all know there are ways in which it could be improved. And I will be pointing to lots of such ways in this seminar. I created ILovePLSQLAnd.net to make it easy for PL/SQL users to influence the future direction of the language. Please use it! http://www.ILovePLSQLAnd.net
  • 4. The agenda C'mon, PL/SQL is not weird. SQLERRM and DBMS_OUTPUT.PUT_LINE Error codes: positive, negative, either, both? The built-in string parsing program - NOT! VARCHAR2 memory allocation VARRAY - what kind of varrying is that? $IF I understood $IF I would be amazing! The mystery of "reserved words" in PL/SQL Where's my line number? Where's my program name? Zero length strings and NULL %ROWTYPE and %TYPE
  • 5. C'mon, PL/SQL is not WEIRD! That's true. It really isn't a weird language. Anybody ever use LISP? In fact, it is a very readable, accessible and enjoyable language. It is also a very robust and powerful language. All thanks to the PL/SQL dev team! So when I make fun of certain aspects of PL/SQL, I do it out of the deepest respect and appreciation - and desire to make PL/SQL even better! Thank you, PL/SQL Dev Team!
  • 6. PL/SQL - the Really Readable Language Let's compare Java and PL/SQL.... public class Hello { public static void main ( String [] args ) { System . out . println ( "Hello World!" ); } } CREATE OR REPLACE PROCEDURE hello ( IS BEGIN DBMS_OUTPUT.PUT_LINE ('Hello world!'); END hello ; PL/SQL isn't as powerful as Java, but it's much easier to write - and understand!
  • 7. SQLERRM and DBMS_OUTPUT.PUT_LINE SQLERRM returns the error text for the specified error code. If none is provided, then SQLCODE is assumed. But SQLERRM might truncate your error message! Currently at 512, earlier at 255. 255...255...what does that number remind us of! Ah, yes: DBMS_OUTPUT.PUT_LINE So use DBMS_UTILITY.FORMAT_ERROR_STACK instead! sqlerrm.sql
  • 8. Error codes: positive, negative, either, both? We all know that Oracle errors are negative. Well, except for 1 and 100. Hey, that NO_DATA_FOUND is pretty strange all by itself! Oh, and error codes saved by SAVE EXCEPTIONS. And error codes saved by DBMS_ERRLOG At least the EXCEPTION_INIT pragma has it straight - more or less. STANDARD package in RDBMS\Admin: stdspec.sql stdbody.sql bulkexc.sql dbms_errlog*.* exception_init.sql
  • 9. More on errors: the price of laziness - or is it cost-cutting? It's as if someone at Oracle calculated that declaring new exceptions cost $74 each. Larry: "Save $1B in costs this year!" Developers: "OK, we won't declare new exceptions." And so we have "recycled" exceptions: NO_DATA_FOUND: pure confusion VALUE_ERROR: sub-message text excquiz6*.sql value_error_demo.sql
  • 10. The built-in string parsing program - NOT! Surely any robust programming language provides a program to parse a delimited string. And PL/SQL is no exception.... Well, sort of. Oracle gave us: DBMS_UTILITY.COMMA_TO_TABLE String cannot be NULL - raises error! Only parses comma-delimited strings. Every element in the list must be a valid PL/SQL identifier. You can't make this stuff up! commatotable.tst sqlerrm.sql
  • 11. Parsing programs to the rescue Well, the main thing is that you should not have to write these algorithms over and over yourself. So here are some options: parse.pkg - parse any delimited string, returns a collection of type defined in package. str2list.pkg - parse any delimited string, returns a collection based on your own type . Regular expressions parse.pkg str2list.pkg str2list2.pkg
  • 12. VARCHAR2 memory allocation Memory for VARCHAR2 variables is only allocated as needed, right? Variable-length strings! OK, then which of the following variables consume the most memory? DECLARE l_var1 VARCHAR2 (32767); l_var2 VARCHAR2 (4050); l_var3 VARCHAR2 (500); BEGIN l_var1 := 'a'; l_var2 := 'a'; l_var3 := 'a'; END; / That's right! l_var3
  • 13. VARRAY - what kind of varrying is that? Oracle offers three kinds of collections Associative Array Nested table Varray, a.k.a, "Varrying array" That's weird enough, all by itself, really. But what I find truly odd is the use of the name "varrying array". It is the least varrying of all the different types of collections! associative_array_example.sql nested_table_example.sql varray_example.sql collection_of_records.sql
  • 14. $IF I understood $IF I would be amazing! Have you ever used the $ syntax added to PL/SQL in Oracle10g Release 2? It looks very weird . But it is very useful . With conditional compilation, you can.... Write code that will compile and run under different versions of Oracle (relevant for future releases). Run different code for test, debug and production phases. That is, compile debug statements in and out of your code. Expose private modules for unit testing. cc_version_check.sql cc_debug_trace.sql 11g_emplu.pkg
  • 15. The mystery of "reserved words" in PL/SQL What will happen when I run this code? DECLARE PLS_INTEGER VARCHAR2 (1); NO_DATA_FOUND EXCEPTION; BEGIN SELECT dummy INTO PLS_INTEGER FROM DUAL WHERE 1 = 2; IF PLS_INTEGER IS NULL THEN RAISE NO_DATA_FOUND; END IF; EXCEPTION WHEN NO_DATA_FOUND THEN DBMS_OUTPUT.put_line ('No dummy!'); END; excquiz5.sql
  • 16. Exploring the STANDARD package Much of what we consider to be the base PL/SQL language is defined in the STANDARD package. One of two "default" packages; the other is DBMS_STANDARD. You can view the contents of the STANDARD package (and other "supplied" packages by visiting the appropriate variation of: $ORACLE_HOME/Rdbms/Admin
  • 17. Where's my line number? An exception is raised. I trap it and log the error. I want to see the line number on which the error is raised. If I am not yet on Oracle 10g Release 2, I am totally out of luck. Keep up with Oracle, though, and then you can take advantage of DBMS_UTILITY.FORMAT_ERROR_BACKTRACE Call it every time you log an error! Backtrace.sql Quest Error Manager - www.ToadWorld.com - Downloads
  • 18. Where's my program name? DBMS_UTILITY.FORMAT_CALL_STACK answers the question: "How did I get here?" DBMS_UTILITY.FORMAT_ERROR_BACKTRACE answers the question: "Where did my error come from?" But in both cases....if the program in question is located inside a package, I don't see the name of that subprogram. Please, Oracle, give me my program name! Heck, and my overloading, while you are at it.
  • 19. Zero length strings and NULL A NULL string and a zero length string ( '' ) are supposed to be treated the same way inside Oracle. And for the most part it is true. But when it comes to ORA-06502: PL/SQL: numeric or value error: NULL index table key value You can get some rather weird behavior! Especially on Oracle11g.... null_index_value.sql zero_length_string.sql
  • 20. %TYPE and %ROWTYPE? I have enormous respect for the PL/SQL team. Not only are they are all smarter than me, they are real computer scientists. I am an amateur by comparison. And their design of the PL/SQL syntax is for the most part very elegant and minimalist. But why do we have to have both %TYPE and %ROWTYPE?
  • 21. So I hope you now agree with me... PL/SQL can be a little bit weird sometimes. But it is still a truly elegant and straightforward language. Those features make it, in turn, accessible and productive . And that's why so many of us have achieved personal success , and have implemented so many successful applications with the PL/SQL language.