﻿<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Steven Feuerstein's Blog</title>
    <description>&lt;table cellspacing="1" cellpadding="1"&gt;
        &lt;tr&gt;
            &lt;td valign="top"&gt;&lt;img height="183" alt="" width="139" src="/Portals/0/Blog/blog-steven-feuerstein.png" /&gt;&lt;/td&gt;
            &lt;td valign="top"&gt;Steven Feuerstein is considered one of the world's leading experts on the Oracle PL/SQL language, having written ten books on PL/SQL (all published by O'Reilly Media, including Oracle PL/SQL Programming. Steven has been developing software since 1980, spent five years with Oracle (1987-1992) and has served as PL/SQL Evangelist for Quest Software since January 2001. He is also an Oracle ACE Director. He writes regularly for Oracle Magazine, which named him the PL/SQL Developer of the Year in both 2002 and 2006.
            &lt;p&gt;&amp;#160;Steven's blog provides advice and code that you can put to immediate use in your world of programming.&amp;#160;&lt;/p&gt;
            &lt;p&gt;&lt;font color="#003366" size="3"&gt;&lt;strong&gt;Recent postings on his  PL/SQL Obsession:&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
&lt;/table&gt;</description>
    <link>http://www.toadworld.com/BLOGS/tabid/67/BlogId/13/Default.aspx</link>
    <language>en-US</language>
    <managingEditor>Steven Feuerstein</managingEditor>
    <webMaster>webmaster@toadworld.com</webMaster>
    <pubDate>Sun, 14 Mar 2010 16:55:39 GMT</pubDate>
    <lastBuildDate>Sun, 14 Mar 2010 16:55:39 GMT</lastBuildDate>
    <docs>http://backend.userland.com/rss</docs>
    <generator>Blog RSS Generator Version 3.2.0.15477</generator>
    <item>
      <title>Error Management functions and features for PL/SQL Developers</title>
      <description>&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma"&gt;Winter is descending on &lt;st1:city w:st="on"&gt;&lt;st1:place w:st="on"&gt;Chicago&lt;/st1:place&gt;&lt;/st1:city&gt;; we had our first snow (flurries, really) on Thanksgiving Day, and the sun is weak. For many, this is a depressing time – and I mean that the lack of that and cold actually does make people feel depressed. Perhaps that is why I found myself thinking negatively – that is, about exceptions in PL/SQL.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma"&gt;So I thought I would share with you some of the features and functions available in PL/SQL, especially those introduced in recent versions of Oracle, which will help you trap and log error information.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma"&gt;For each of the topics below, I describe them briefly and then point to files in my demo.zip archive that illustrate the technique, and also the hyperlink to Oracle documentation on the topic.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma"&gt;You can download my demo.zip archive by clicking &lt;a href="http://www.toadworld.com/LinkClick.aspx?fileticket=WdgBQ7kABao=&amp;tabid=155"&gt;here&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma"&gt;Enjoy! And remember: never be sad about Oracle exceptions. Just make sure you have a powerful, general utility for raising, handling and logging those errors. If you don't already have such a thing, then please do download and try the freeware &lt;a href="http://www.toadworld.com/Education/StevenFeuersteinsPLSQLObsession/MyPetProjectsandContributions/QuestErrorManagerQEM/tabid/210/Default.aspx"&gt;Quest Error Manager&lt;/a&gt;. I wrote it myself – just for you!&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma"&gt;&lt;strong&gt;Save DML errors to a log table instead of raising an exception (Oracle10g)&lt;/strong&gt;&lt;br /&gt;
&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma"&gt;As soon as the SQL engine raises an exception from processing a DML statement, your executable section terminates. You can, of course, trap the exception, log it, and then keep going, but once an exception is raised, performance degrades terribly.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma"&gt;Use the DBMS_ERRLOG package to define an error log table for your own table. Then when you write your DML statement, include the LOG ERRORS clause. With this approach, Oracle will save DML errors to a log table instead of raising an exception; your program will finish more quickly and then afterwards, you can query the information from the log table and either log the errors in your own system, try to recover or display error information.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma"&gt;&lt;strong&gt;My demo.zip files of relevance&lt;br /&gt;
&lt;/strong&gt;&lt;/span&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma"&gt;dbms_errlog*.*&lt;br /&gt;
&lt;/span&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma"&gt;forall_with_dbms_errlog.sql&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt; &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma"&gt;Oracle documentation reference&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt; &lt;/strong&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma"&gt;&lt;a target="_blank" href="http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_errlog.htm%23sthref2860"&gt;http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_errlog.htm#sthref2860&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma"&gt;&lt;strong&gt;Save exceptions till the end of your FORALL execution&lt;o:p&gt;&lt;/o:p&gt;&lt;/strong&gt;&lt;/span&gt; &lt;br /&gt;
&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma"&gt;FORALL is an absolutely, deliriously wonderful enhancement to DML execution introduced in Oracle8i. With FORALL, you can execute multiple DML statements in "bulk," which means they run in a fraction of the time it would take if they ran them on a row by row basis.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma"&gt;As with LOG ERRORS above, you can tell FORALL to continue past any exceptions encountered as it runs each DML operation by adding the SAVE EXCEPTIONS clause.&lt;span style="mso-spacerun: yes"&gt;  &lt;/span&gt;Then if one or more exceptions were encountered, when FORALL is done, Oracle will raise the ORA-24381 error and also populates a "pseudo-collection" called SQL%BULK_EXCEPTIONS with the error code and the index in the collection that raised the error.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma"&gt;&lt;strong&gt;My demo.zip files of relevance&lt;o:p&gt;&lt;/o:p&gt;&lt;/strong&gt;&lt;/span&gt; &lt;br /&gt;
&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma"&gt;cfl_to_bulk*.sql&lt;br /&gt;
&lt;/span&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma"&gt;bulkexc.sql&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;strong&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma"&gt;Oracle documentation reference&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt; &lt;/strong&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma"&gt;&lt;a target="_blank" href="http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/tuning.htm%23sthref2201"&gt;http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/tuning.htm#sthref2201&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma"&gt;&lt;strong&gt;Find the line number on which the error was raised (Oracle10g)&lt;o:p&gt;&lt;/o:p&gt;&lt;/strong&gt;&lt;/span&gt; &lt;br /&gt;
&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma"&gt;Call the DBMS_UTILITY.FORMAT_ERROR_BACKTRACE to retrieve a string that shows the stack of calls that trace back to the line number and program name from which the most recent error was raised.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma"&gt;&lt;strong&gt;My demo.zip files of relevance&lt;o:p&gt;&lt;/o:p&gt;&lt;/strong&gt;&lt;/span&gt; &lt;br /&gt;
&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma"&gt;backtrace*.sql&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma"&gt;&lt;strong&gt;Oracle documentation reference&lt;o:p&gt;&lt;/o:p&gt;&lt;/strong&gt;&lt;/span&gt; &lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma"&gt;&lt;a target="_blank" href="http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_util.htm%23sthref9387"&gt;http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_util.htm#sthref9387&lt;/a&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma"&gt;&lt;strong&gt;Get the error message&lt;o:p&gt;&lt;/o:p&gt;&lt;/strong&gt;&lt;/span&gt; &lt;br /&gt;
&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma"&gt;What? You thought you should call the SQLERRM function? No way! Oracle recommends that you not use this function, because it might truncate your error message. Instead, call the DBMS_UTILITY.FORMAT_ERROR_STACK function and it will return the full error message (and sometimes even a stack!).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma"&gt;My demo.zip files of relevance&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/strong&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma"&gt;Sorry, none! It's such an easy, little thing to use...&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma"&gt;&lt;strong&gt;Oracle documentation reference&lt;o:p&gt;&lt;/o:p&gt;&lt;/strong&gt;&lt;/span&gt; &lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Tahoma; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;&lt;a target="_blank" href="http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_util.htm%23sthref9392"&gt;http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_util.htm#sthref9392&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;</description>
      <link>http://www.toadworld.com/BLOGS/tabid/67/EntryID/159/Default.aspx</link>
      <author>Steven Feuerstein</author>
      <comments>http://www.toadworld.com/BLOGS/tabid/67/EntryID/159/Default.aspx#Comments</comments>
      <guid isPermaLink="true">http://www.toadworld.com/Default.aspx?tabid=67&amp;EntryID=159</guid>
      <pubDate>Wed, 05 Dec 2007 03:41:00 GMT</pubDate>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.toadworld.com/DesktopModules/Blog/Trackback.aspx?id=159</trackback:ping>
    </item>
  </channel>
</rss>