<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Oracle WTF</title><link>http://oracle-wtf.blogspot.com/</link><description>Let's hear it for consultants</description><language>en</language><managingEditor>noreply@blogger.com (William Robertson)</managingEditor><lastBuildDate>Thu, 18 Jun 2009 23:06:20 PDT</lastBuildDate><generator>Blogger http://www.blogger.com</generator><openSearch:totalResults xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">86</openSearch:totalResults><openSearch:startIndex xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">1</openSearch:startIndex><openSearch:itemsPerPage xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/blogspot/DVBI" type="application/rss+xml" /><feedburner:browserFriendly>This is an XML content feed. It is intended to be viewed in a newsreader or syndicated to another site, subject to copyright and fair use.</feedburner:browserFriendly><item><title>The Undocumented "/1000" currency formatting function</title><link>http://feedproxy.google.com/~r/blogspot/DVBI/~3/UhKZ7KBEhfs/undocumented-1000-currency-formatting.html</link><author>noreply@blogger.com (William Robertson)</author><pubDate>Sun, 03 May 2009 04:32:55 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-15861274.post-6684392869768607105</guid><description>&lt;p&gt;&lt;a href="http://forums.oracle.com/forums/thread.jspa?threadID=890147"&gt;Forum question&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Hi,&lt;/p&gt;&lt;p&gt;How can I format currency values to shorthand?&lt;/p&gt;&lt;p&gt;i.e. how can I display 12500 as 12.5, 2700 as 2.7, 700 as 0.7 etc?&lt;/p&gt;&lt;p&gt;I have tried using various masks but can't achieve the results I'm looking for.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;That's a tough one. How to make 700 into 0.7? Could there be some Oracle feature to help with this?&lt;/p&gt;&lt;p&gt;Two quick replies later:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Thanks for the replies guys&lt;/p&gt;&lt;p&gt;I wasnt aware of the "/1000" feature, but it has done exactly what I need.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Oracle needs to do more to promote these display format features. What else are they hiding? That's what we want to know.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15861274-6684392869768607105?l=oracle-wtf.blogspot.com'/&gt;&lt;/div&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">3</thr:total><feedburner:origLink>http://oracle-wtf.blogspot.com/2009/05/undocumented-1000-currency-formatting.html</feedburner:origLink></item><item><title>How to talk your way out of a hole</title><link>http://feedproxy.google.com/~r/blogspot/DVBI/~3/BJCYZLDvROA/how-to-talk-your-way-out-of-hole.html</link><author>noreply@blogger.com (William Robertson)</author><pubDate>Fri, 10 Apr 2009 00:32:34 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-15861274.post-7526221537717579389</guid><description>&lt;p&gt;One last shot from our favourite &lt;a href="http://oracle-wtf.blogspot.com/2009/03/consultant-on-backups.html"&gt;consultant&lt;/a&gt;:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Be careful what you expect from this proof of concept. We can’t prove the performance will match the requirements, and I would argue that performance isn’t a function of this architecture, it’s a function of technology.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;The issue is not the architecture, it’s that [this company] doesn’t have the technology. I would even argue that the technology required might not exist yet.&lt;p&gt;&lt;/p&gt;&lt;p&gt;We can say that indicatively if the technology did exist, then this architecture would hit that performance requirement.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Let's hear it for &lt;a href="http://www.joelonsoftware.com/items/2008/05/01.html"&gt;architecture astronauts&lt;/a&gt;.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15861274-7526221537717579389?l=oracle-wtf.blogspot.com'/&gt;&lt;/div&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://oracle-wtf.blogspot.com/2009/04/how-to-talk-your-way-out-of-hole.html</feedburner:origLink></item><item><title>Rollback segments explained</title><link>http://feedproxy.google.com/~r/blogspot/DVBI/~3/5SGO2lFpT_0/rollback-segments-explained.html</link><author>noreply@blogger.com (William Robertson)</author><pubDate>Fri, 20 Mar 2009 01:03:11 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-15861274.post-7945167208236007944</guid><description>&lt;p&gt;I recently read this in a book about data warehousing:&lt;/p&gt;&lt;blockquote&gt;&lt;h3 style="margin-top: 0.5em;margin-bottom: 1em;"&gt;Source System Rollback Segments&lt;/h3&gt;When extracting from a relational source, extracts that take a long time can be problematic. If an extract asks for all records updated in the last 24 hours, the system must locate the appropriate set of records. This means that no user can change the updated_date field while your query is being processed. As transactions flow in during your query, they are queued up in a separate place called a rollback segment, to be applied once your request is finished. If your query takes too long, this queue gets too large and runs out of space. The system then kills your job and processes the transactions that have been queued up. In general, the folks responsible for the transaction system don't like this kind of behavior.&lt;/blockquote&gt;&lt;p&gt;Now to be fair, the book was published in 1998 and is not specifically about Oracle. Does anyone know whether there has ever been a commercial DBMS that worked anything like this, or did they just make it up?&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15861274-7945167208236007944?l=oracle-wtf.blogspot.com'/&gt;&lt;/div&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">8</thr:total><feedburner:origLink>http://oracle-wtf.blogspot.com/2009/03/rollback-segments-explained.html</feedburner:origLink></item><item><title>The Consultant on Backups</title><link>http://feedproxy.google.com/~r/blogspot/DVBI/~3/wlE_osT9lYY/consultant-on-backups.html</link><author>noreply@blogger.com (William Robertson)</author><pubDate>Sat, 14 Mar 2009 10:32:26 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-15861274.post-8876133168218652012</guid><description>&lt;p&gt;Our correspondent overheard &lt;a href="http://oracle-wtf.blogspot.com/2009/02/consultant.html"&gt;The Consultant&lt;/a&gt; sorting out the backup requirements for the new system:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;b&gt;Consultant:&lt;/b&gt; You have a 6 hour window overnight, now as the queues get longer under heavy loading the end of day queue clearing will run into that 6 hours. Your backup window will start to get squeezed, so we need to know the minimum time to back-up this amount of data, including the time to shut down and start up the databases.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Technical guy:&lt;/b&gt; Why?&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Consultant:&lt;/b&gt; Because it has to take place in that 6 hour window.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Technical guy:&lt;/b&gt; Why is that?&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Consultant:&lt;/b&gt; Because then the users will come back on line and want to use the system.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Technical guy:&lt;/b&gt; So?&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Consultant: &lt;/b&gt;They can't use the system if it's down to be backed up.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Technical guy: &lt;/b&gt;We'll use an online backup and they can do whatever they like.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Consultant:&lt;/b&gt; Well, if I was in auditing I'd fire you right now. You simply have to shut a database down to back it up. It's the only way you can get a consistent backup.&lt;/p&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15861274-8876133168218652012?l=oracle-wtf.blogspot.com'/&gt;&lt;/div&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://oracle-wtf.blogspot.com/2009/03/consultant-on-backups.html</feedburner:origLink></item><item><title>The Consultant</title><link>http://feedproxy.google.com/~r/blogspot/DVBI/~3/8PR_1GaBY0w/consultant.html</link><author>noreply@blogger.com (William Robertson)</author><pubDate>Sun, 03 May 2009 11:02:22 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-15861274.post-8844457069260996002</guid><description>&lt;p&gt;The Consultant has a Ph. D, vast experience of high-performance systems architecture, a black belt in karate and a reputation as a genius. He's been brought in by senior management at vast but necessary expense for a strategic rethink of the way data is shared between systems, while implementing SOA, improving performance and finding the Higgs Boson. Needless to say, he tends towards the view that database development is overrated. He's already sorted out the data warehouse. Overheard by our correspondent:
&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;I’ve finished the design for the data warehouse. Although I say design, it’s pretty simple. That’s why it was so quick. All data warehouses are essentially the same in that they are a dimensional model. That means that you essentially have everything that is a fact, an immutable fact [waves arms expressively], in the fact table. Just the one, big, table. That’s why they’re so attractive as reporting solutions - everything is in the same place so it’s easy to understand and the reporting is easy to automate. So in that fact table you’ve got all trades, the cashflows, positions, accounting information, accounts, exceptions, counterparties. Anything that’s a fact goes in that table [does wide googly eyes expression with dramatic pause]. Then anything derived is called a dimension, like for instance P&amp;amp;L calculations, whether the account is on balance sheet, or off... they go in the dimension table.  Basically all we have to do is just pump messages into that fact table from the bus and then recalculate the dimensions in the dimension table periodically, and that’s the technical job. Getting the facts in there and getting the calculations done.&lt;/p&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15861274-8844457069260996002?l=oracle-wtf.blogspot.com'/&gt;&lt;/div&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">4</thr:total><feedburner:origLink>http://oracle-wtf.blogspot.com/2009/02/consultant.html</feedburner:origLink></item><item><title>More Fake Performance Tips</title><link>http://feedproxy.google.com/~r/blogspot/DVBI/~3/6u_xSBv8Bpc/more-fake-performance-tips.html</link><author>noreply@blogger.com (William Robertson)</author><pubDate>Mon, 03 Nov 2008 00:33:06 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-15861274.post-7219476775729158465</guid><description>&lt;p&gt;We're not sure if this is a joke or just (more likely) the work of an idiot. Here are &lt;a href="http://latest360.blogspot.com/2008/04/tips-for-better-performance-and-tuning.html" ref="nofollow"&gt;15 Tips for better performance and tuning in Oracle SQL and PL/SQL&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;&lt;ol&gt;
&lt;li&gt;FTS (Full Table Scans) are always bad and Index usage is always good.&lt;/li&gt;
&lt;li&gt;Usage of dynamic SQL within the stored procedure code is always bad even for search procedures.&lt;/li&gt;
&lt;li&gt;Empty Space in an index that gets created due to the DML operations do not get used.&lt;/li&gt;
&lt;li&gt;Indexes should be rebuilt at regular intervals.&lt;/li&gt;
&lt;li&gt;Indexes and statistics are the same thing. Also, histograms are needed only on indexed columns.&lt;/li&gt;
&lt;li&gt;Usage of cursors is always bad so avoid them like the plague.&lt;/li&gt;
&lt;li&gt;Truncate command cannot be rolled back because it is a non-logged operation.&lt;/li&gt;
&lt;li&gt;Table variables in SQL Server are always only memory resident.&lt;/li&gt;
&lt;li&gt;Column order in a covered index does not matter.&lt;/li&gt;
&lt;li&gt;In the case of SQL Server, one can separate the clustered index from the table.&lt;/li&gt;
&lt;li&gt;Only committed data gets written to the disk.&lt;/li&gt;
&lt;li&gt;Logical I/Os (LIO) are not a cause of concern, only Physical IO (PIO) are.&lt;/li&gt;
&lt;li&gt;Count(1) is better performing than count(*).&lt;/li&gt;
&lt;li&gt;Issue frequent commits in the application to make the transaction faster and also improve concurrency.&lt;/li&gt;
&lt;li&gt;Views are evil evil DB Objects that always slow down performance. &lt;/li&gt;&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;p&gt;We like the fact that 8, 9 and 10 appear to be about SQL Server, despite the heading. Probably Nawal could only think of 12 fake Oracle tips but thought nobody would notice. Can you help him out with some more misleading tips for Oracle? (Or SQL Server. Nobody will notice.) For example,&lt;/p&gt;&lt;ol start="16"&gt;
&lt;li&gt;The buffer cache hit ratio is a reliable indicator of system performance.&lt;/li&gt;
&lt;li&gt;Bitmap indexes are perfect for columns with a small number of distinct values, like 'Y' and 'N'.&lt;/li&gt;
&lt;li&gt;The Inuit have fifty words for snow.
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Spotted by Michel Cadot on Oracle-L.&lt;/p&gt;
&lt;p style="font-style: italic;"&gt;&lt;b&gt;Update:&lt;/b&gt; Yong Huang pointed out that the source of the article appears to be a list of common myths posted on a SQL Server blog, which makes it slightly less funny than it first seemed. Oh well.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15861274-7219476775729158465?l=oracle-wtf.blogspot.com'/&gt;&lt;/div&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">4</thr:total><feedburner:origLink>http://oracle-wtf.blogspot.com/2008/11/more-fake-performance-tips.html</feedburner:origLink></item><item><title>TGI g_friday</title><link>http://feedproxy.google.com/~r/blogspot/DVBI/~3/ZLQNuazt-Hs/tgi-gfriday.html</link><author>noreply@blogger.com (William Robertson)</author><pubDate>Fri, 01 Aug 2008 04:04:36 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-15861274.post-732908617249311457</guid><description>&lt;p&gt;Found in a package body:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;g_friday CONSTANT VARCHAR2(6) := 'Friday';&lt;/pre&gt;&lt;/blockquote&gt;
&lt;p&gt;...then a couple of hundred lines later:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;if to_char(business_date,'fmDay') = g_friday then
    &lt;i&gt;...end-of-week processing...&lt;/i&gt;
else
    &lt;i&gt;...regular processing...&lt;/i&gt;
end if;&lt;/pre&gt;&lt;/blockquote&gt;
&lt;p&gt;Now that's flexible. If end-of-week processing is ever moved to the weekend, all you have to do is set &lt;tt&gt;g_friday := 'Saturday'&lt;/tt&gt;.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15861274-732908617249311457?l=oracle-wtf.blogspot.com'/&gt;&lt;/div&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">10</thr:total><feedburner:origLink>http://oracle-wtf.blogspot.com/2008/08/tgi-gfriday.html</feedburner:origLink></item><item><title>Auxiliary Constructs Appeal</title><link>http://feedproxy.google.com/~r/blogspot/DVBI/~3/BOwlZvhlfg0/auxiliary-constructs-appeal.html</link><author>noreply@blogger.com (William Robertson)</author><pubDate>Sun, 03 May 2009 11:12:54 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-15861274.post-5907826070431757676</guid><description>&lt;p&gt;Will somebody give &lt;a href="http://forums.oracle.com/forums/thread.jspa?messageID=2597237"&gt;this guy&lt;/a&gt; some auxiliary constructs? He just needs to know what's the auxiliary constructs, and examples in the auxiliary constructs. So if you have any auxiliary constructs you don't need, now's the time to dig deep. The appeal starts here.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15861274-5907826070431757676?l=oracle-wtf.blogspot.com'/&gt;&lt;/div&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">10</thr:total><feedburner:origLink>http://oracle-wtf.blogspot.com/2008/06/auxiliary-constructs-appeal.html</feedburner:origLink></item><item><title>Fine tuning</title><link>http://feedproxy.google.com/~r/blogspot/DVBI/~3/dHC6Lvrrx8k/fine-tuning.html</link><author>noreply@blogger.com (William Robertson)</author><pubDate>Sat, 03 May 2008 08:41:15 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-15861274.post-3669780349250863678</guid><description>&lt;p&gt;Mike is doing some work on an application that started life as SQL Server. Now that it has been converted to Oracle, there are one or two bits that could still do with a little fine tuning.&lt;/p&gt;&lt;p&gt;One particular procedure seemed to take rather a lot of time, and several developers had tried to get better performance out of it without much success. Here it is:&lt;/p&gt;&lt;blockquote&gt;
&lt;pre&gt;CREATE OR REPLACE PROCEDURE getupdatedrunids
    ( p_customer_id  IN VARCHAR2 DEFAULT NULL
    , pc_results_out IN OUT SYS_REFCURSOR )
AS
    v_fetch_status     INTEGER := 0;
    v_sql_status       INTEGER;
    v_fetch_status1    INTEGER := 0;
    v_sql_status1      INTEGER;
    v_event_id         VARCHAR2(50);
    v_runid            NUMBER(10, 0);
    v_count_run_conns  INTEGER := 0;
    v_temp_runs        INTEGER;

BEGIN
    DELETE FROM temp_runs;

    DELETE FROM temp_run_connections;

    INSERT INTO temp_runs
         ( run_id )
    SELECT DISTINCT i.run_id
    FROM   event_status i
         , run_status    b
    WHERE  i.run_id = b.run_id
    AND    i.event_id IN
           ( SELECT DISTINCT i.event_id
             FROM   event_status i
                  , run_status   b
             WHERE  i.run_id = b.run_id
             AND    b.customer_id = p_customer_id
             GROUP  BY i.event_id
             HAVING COUNT(i.run_id) &gt; 1)
             AND    b.customer_id = p_customer_id;

    BEGIN
        v_temp_runs := 0;
        SELECT COUNT(*)
        INTO   v_temp_runs
        FROM   dual
        WHERE  EXISTS
               ( SELECT *
                 FROM   temp_runs );
    END;

    IF v_temp_runs &gt; 0 THEN
    
        DECLARE
            CURSOR c_runs IS
                SELECT DISTINCT run_id
                FROM   temp_runs;
        BEGIN
            OPEN c_runs;
            FETCH c_runs INTO v_runid;

            IF c_runs%NOTFOUND
            THEN
                v_sql_status1   := 2;
                v_fetch_status1 := -1;
            ELSE
                v_sql_status1   := 0;
                v_fetch_status1 := 0;
            END IF;
        
            WHILE v_fetch_status1 = 0
            LOOP
                BEGIN
                    DECLARE
                        CURSOR cust_incidents_cs IS
                        
                            SELECT DISTINCT i.event_id
                            FROM   event_status i
                            WHERE  i.run_id = v_runid
                            AND    i.rejected = 0;
                    BEGIN
                        OPEN cust_incidents_cs;
                    
                        FETCH cust_incidents_cs INTO v_event_id;

                        IF cust_incidents_cs%NOTFOUND
                        THEN
                            v_sql_status   := 2;
                            v_fetch_status := -1;
                        ELSE
                            v_sql_status   := 0;
                            v_fetch_status := 0;
                        END IF;

                        &amp;lt;&amp;lt;i_loop1&gt;&gt;
                        WHILE v_fetch_status = 0
                        LOOP
                            BEGIN
                                INSERT INTO temp_run_connections
                                     ( run_id
                                     , connectedids)
                                SELECT DISTINCT v_runid
                                     , i.run_id AS connectedids
                                FROM   event_status i
                                WHERE  i.run_id &amp;lt; v_runid
                                AND    i.event_id = v_event_id
                                AND    i.rejected = 0
                                AND    i.run_id IN
                                       ( SELECT DISTINCT run_id
                                         FROM   temp_runs );

                                &amp;lt;&amp;lt;fetchnext&gt;&gt;
                                FETCH cust_incidents_cs INTO v_event_id;

                                IF cust_incidents_cs%NOTFOUND
                                THEN
                                    v_sql_status   := 2;
                                    v_fetch_status := -1;
                                ELSE
                                    v_sql_status   := 0;
                                    v_fetch_status := 0;
                                END IF;
                            END;
                        END LOOP;

                        CLOSE cust_incidents_cs;
                    END;
                
                    FETCH c_runs INTO v_runid;

                    IF c_runs%NOTFOUND
                    THEN
                        v_sql_status1   := 2;
                        v_fetch_status1 := -1;
                    ELSE
                        v_sql_status1   := 0;
                        v_fetch_status1 := 0;
                    END IF;
                END;
            END LOOP;
            CLOSE c_runs;
        END;
    END IF;

    SELECT COUNT(*)
    INTO   v_count_run_conns
    FROM   temp_run_connections;

    IF v_count_run_conns &gt; 0
    THEN
        OPEN pc_results_out FOR
            SELECT DISTINCT run_id, connectedids
            FROM   temp_run_connections;
    END IF;

END getupdatedrunids;&lt;/pre&gt;&lt;/blockquote&gt;&lt;p&gt;His final version was much faster. See if you can spot the difference:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;CREATE OR REPLACE PROCEDURE getupdatedrunids
    ( p_customer_id  IN VARCHAR2 DEFAULT NULL
    , pc_results_out IN OUT SYS_REFCURSOR )
AS
BEGIN
    OPEN pc_results_out FOR
        SELECT DISTINCT e2.run_id, ic.run_id AS connectedids
        FROM   run_status r1
             , run_status r2
             , event_status e1
             , event_status e2
        WHERE  r1.customer_id = p_customer_id
        AND    r2.customer_id = r1.customer_id
        AND    e1.run_id = r2.run_id
        AND    e1.rejected = 0
        AND    e2.run_id = r1.run_id
        AND    e2.event_id = e1.event_id
        AND    e2.run_id &gt; e1.run_id
        AND    e2.rejected = 0
        ORDER BY 1, 2;

END getupdatedrunids;&lt;/pre&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15861274-3669780349250863678?l=oracle-wtf.blogspot.com'/&gt;&lt;/div&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">7</thr:total><feedburner:origLink>http://oracle-wtf.blogspot.com/2008/04/fine-tuning.html</feedburner:origLink></item><item><title>WREAK_APPLICATION_HAVOC</title><link>http://feedproxy.google.com/~r/blogspot/DVBI/~3/GprNx9w8La4/wreakapplicationhavoc.html</link><author>noreply@blogger.com (William Robertson)</author><pubDate>Sun, 10 Feb 2008 11:36:24 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-15861274.post-118925958724705034</guid><description>&lt;p&gt;&lt;a href="http://tkyte.blogspot.com/2008/01/why-do-people-do-this.html"&gt;Tom Kyte recently blogged&lt;/a&gt; about the senseless and yet strangely common practice of coding something like this:&lt;/p&gt;&lt;pre&gt;WHEN OTHERS THEN
   RAISE_APPLICATION_ERROR(-20001,'Following Error Occured:' || SQLERRM);&lt;/pre&gt;
&lt;p&gt;which fairly obviously achieves nothing except take a standard message like this:&lt;/p&gt;&lt;pre&gt;ORA-06501: PL/SQL: program error
ORA-06512: at line 6&lt;/pre&gt;&lt;p&gt;and pointlessly scramble it into this:&lt;/p&gt;&lt;pre&gt;ORA-20001:&amp;nbsp;Following&amp;nbsp;Error&amp;nbsp;Occured:ORA-06501:&amp;nbsp;PL/SQL:&amp;nbsp;program&amp;nbsp;error
ORA-06512:&amp;nbsp;at&amp;nbsp;line&amp;nbsp;11&lt;/pre&gt;&lt;p&gt;which adds some meaningless text, hides the original line number, and miss-spells "occurred". Not bad for a day's work.&lt;/p&gt;&lt;p&gt;It turned out that some people had been doing this for years because they were simply too stupid to realise that they didn't have to.&lt;/p&gt;&lt;p&gt;Anyway you know all this because you read Tom Kyte's blog. But have a look at &lt;a href="http://www.techonthenet.com/oracle/exceptions/sqlerrm.php" rel="nofollow"&gt;this helpful page of advice&lt;/a&gt; from Tech On The Net, under &lt;i&gt;"Oracle/PLSQL: SQLERRM Function"&lt;/i&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;You could use the SQLERRM function to raise an error as follows:&lt;/p&gt;&lt;pre&gt;EXCEPTION
   WHEN OTHERS THEN
      raise_application_error
      (-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
END;&lt;/pre&gt;&lt;p&gt;Or you could log the error to a table as follows:&lt;/p&gt;&lt;pre&gt;EXCEPTION
   WHEN OTHERS THEN
      err_code := SQLCODE;
      err_msg := substr(SQLERRM, 1, 200);

      INSERT INTO audit_table (error_number, error_message)
      VALUES (err_code, err_msg);
END;&lt;/pre&gt;&lt;/blockquote&gt;&lt;p&gt;Now that is even better. The first example adds some meaningless text, hides the original line number, and duplicates the error code (unless it's a NO_DATA_FOUND exception, but let's not go there), to produce something like this:&lt;/p&gt;
&lt;pre&gt;ORA-20001:&amp;nbsp;An&amp;nbsp;error&amp;nbsp;was&amp;nbsp;encountered&amp;nbsp;-&amp;nbsp;-6501&amp;nbsp;-ERROR-&amp;nbsp;ORA-06501:&amp;nbsp;PL/SQL:&amp;nbsp;program&amp;nbsp;error&lt;br&gt;ORA-06512: at line 11&lt;/pre&gt;&lt;p&gt;The error logging example pointlessly captures &lt;tt&gt;SQLCODE&lt;/tt&gt; (nobody will ever use it), throws away all but the first 200 characters of the error stack, logs nothing about what happened, and fails to re-raise the exception so if you don't check the log you won't know anything went wrong until your customers start asking where their stuff is.&lt;/p&gt;
&lt;p&gt;Wouldn't it be great if there were, say, a Boolean third parameter to &lt;a href="http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/errors.htm#sthref2006"&gt;RAISE_APPLICATION_ERROR&lt;/a&gt; that would make it retain the existing error stack, freeing up the message line for you to put something intelligent and helpful, like, I don't know,&lt;/p&gt;
&lt;pre&gt;BEGIN
    RAISE program_error;
EXCEPTION
    WHEN OTHERS THEN
        RAISE_APPLICATION_ERROR
        ( -20001
        , 'Biscuits cannot be ordered on a ' || TO_CHAR(SYSDATE,'fmDay') ||
          ' without a hot beverage'
        , &lt;b&gt;TRUE&lt;/b&gt;);
END;&lt;/pre&gt;&lt;p&gt;to produce something like this:&lt;/p&gt;&lt;pre&gt;ORA-20001: Biscuits cannot be ordered on a Sunday without a hot beverage
ORA-06512: at line 5
ORA-06501: PL/SQL: program error&lt;/pre&gt;&lt;p&gt;We can but dream.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15861274-118925958724705034?l=oracle-wtf.blogspot.com'/&gt;&lt;/div&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">11</thr:total><feedburner:origLink>http://oracle-wtf.blogspot.com/2008/02/wreakapplicationhavoc.html</feedburner:origLink></item><item><title>Frameworkia</title><link>http://feedproxy.google.com/~r/blogspot/DVBI/~3/y55V0FabZwY/frameworkia.html</link><author>noreply@blogger.com (William Robertson)</author><pubDate>Fri, 26 Oct 2007 00:36:04 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-15861274.post-2499204318775308735</guid><description>&lt;p&gt;We thought long and hard about possible titles for &lt;a href="http://forums.oracle.com/forums/thread.jspa?threadID=575556&amp;tstart=0"&gt;this new PL/SQL development standard&lt;/a&gt; proposed on OTN, but we couldn't improve on the one it came with.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;I want share a new IDEA to create a new standard PL/SQL developing:&lt;/p&gt;
&lt;pre&gt;&lt;br&gt;
Function &lt;name&gt;( Standard Buffer) return number
    variable Number;
    variable1 Varchar2;
begin
    variable := get from Standard Buffer;
    variable1 := get from Standard Buffer;

    { make your business }

    put in standard buffer your results
end;&lt;/br&gt;
&lt;/pre&gt;
&lt;p&gt;Give me feedback if you are interested at the new STANDARD called &lt;b&gt;"FRAMEWORKIA"&lt;/b&gt;.&lt;/p&gt;
&lt;p&gt;A lot possibilities are ready.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Do you see the genius of it?&lt;/p&gt;
&lt;p&gt;Er, no.&lt;/p&gt;
&lt;p&gt;Sensing that there were people who still needed convincing, user601181 posted some sample code developed using the new Frameworkia:&lt;/p&gt;
&lt;pre&gt;CREATE OR REPLACE FUNCTION iacore
    ( eobufferia IN OUT typeeodata )
    RETURN NUMBER
IS
    CURSOR cur_getroutingcondition
        ( idc_workflow IN VARCHAR2
        , idc_operation_node IN VARCHAR2 ) IS
        SELECT *
        FROM   wf_condition
        WHERE  id_workflow = idc_workflow
        AND    id_operation_node = idc_operation_node;

    rec_getroutingcondition cur_getroutingcondition%ROWTYPE;

    CURSOR cur_dobufferiaassign
        ( idc_workflow IN VARCHAR2
        , idc_operation_node IN VARCHAR2 ) IS
        SELECT *
        FROM   wf_assignement
        WHERE  id_workflow = idc_workflow
        AND    id_operation_node = idc_operation_node;

    rec_dobufferiaassign cur_dobufferiaassign%ROWTYPE;

    next_node         NUMBER;
    next_node_ck      NUMBER;
    stop_node         NUMBER;
    operation         VARCHAR2(256);
    operation_call    VARCHAR2(256);
    type_node         VARCHAR2(32);
    workflow          VARCHAR2(32);
    line              VARCHAR2(256);
    status_wf_v       VARCHAR2(3);
    pid_chain_node    NUMBER;
    ia_tid            VARCHAR2(64);
    ia_tid_micro      VARCHAR2(64);
    ret_code_default  NUMBER;
    ret_code          NUMBER;
    retval1           NUMBER;
    statementexc      VARCHAR2(256);
    schema_function   VARCHAR2(32);
    package_function  VARCHAR2(32);
    dblink_function   VARCHAR2(32);
    first_node_flag   VARCHAR2(2) := 'NO';
    id_debug_source   NUMBER;
    mapin_keyp        VARCHAR2(1024);

    headerbufferia typebufferia;
    assignbufferia typebufferia;
    checkbufferia  typebufferia;

    rec_wfnode               wf_node%ROWTYPE;
    rec_wffunctionsourcecode wf_function_source_code%ROWTYPE;
    rec_wflogger             wf_logger%ROWTYPE;
    rec_wfbusiness           wf_business%ROWTYPE;
    rec_wffieldmapping       wf_fieldmapping%ROWTYPE;
BEGIN
    headerbufferia := eobufferia(1);

    workflow := frameworkia.getvalue(headerbufferia,'ID_WORKFLOW');

    ---- DETERMINO QUALE NODO INVOCARE
    pid_chain_node := frameworkia.getvalue(headerbufferia,'WF_NODE_ID');

    ----- SE IL NODO E' NULL ALLORA E' IL PRIMO NODO
    IF pid_chain_node IS NULL
    THEN
        -------DETERMINO HANDLER E FILENAME PER IL LOGGER
        SELECT *
        INTO   rec_wflogger
        FROM   wf_logger
        WHERE  id_workflow = workflow;
        -- rec_WfLogger.ID_WORKFLOW
        -- rec_WfLogger.ID_DEBUG_LEVEL
        -- rec_WfLogger.ID_DIRHANDLER
        -- rec_WfLogger.ID_FILENAME

        --------INSERISCO NELL'HEADER
        frameworkia.setvalue
        ( headerbufferia
        , 'ID_DEBUG_WF'
        , rec_wflogger.id_debug_level );

        frameworkia.setvalue
        ( headerbufferia
        , 'ID_DIRHANDLER'
        , rec_wflogger.id_dirhandler );

        frameworkia.setvalue
        ( headerbufferia
        , 'ID_FILENAME'
        , rec_wflogger.id_filename );

        frameworkia.setvalue
        ( headerbufferia
        , 'CHARACTER_EVIDENCE'
        , '§§§§§§§§§§§§§§§§§§§§' );

        -------DETERMINO L'ID NODE
        SELECT wf_node_id
        INTO   pid_chain_node
        FROM   wf_node
        WHERE  id_workflow = workflow
        AND    wf_first_node = 'YES';

        SELECT *
        INTO   rec_wfnode
        FROM   wf_node
        WHERE  id_workflow = workflow
        AND    wf_first_node = 'YES';

        frameworkia.setvalue
        ( headerbufferia
        , 'WF_NODE_ID'
        , rec_wfnode.wf_node_id );

        SELECT b.status
        INTO   status_wf_v
        FROM   wf_node a
             , wf_name b
        WHERE  a.id_workflow = workflow
        AND    a.wf_node_id = rec_wfnode.wf_node_id
        AND    a.id_workflow = b.id_workflow;

        IF status_wf_v = 'OFF'
        THEN
            RETURN -1;
        END IF;

        ia_tid := frameworkia.getvalue(headerbufferia,'IA_TID');
        ret_code_default := 0;
        ret_code         := 0;

        frameworkia.setvalue
        ( headerbufferia
        , 'RET_CODE_DEFAULT'
        , ret_code_default );

        frameworkia.setvalue
        ( headerbufferia
        , 'RET_CODE'
        , ret_code);

        IF ia_tid IS NULL
        THEN
            ia_tid := 'TIA' || dbms_random.STRING('U',1 * 1 + 6) ||
                      TO_CHAR(SYSTIMESTAMP,'YYYYMMDDHH24MISSFF6');

            frameworkia.setvalue
            ( headerbufferia
            , 'IA_TID'
            , ia_tid );
        END IF;&lt;/pre&gt;
&lt;p&gt;That's just the first hundred lines, and I've formatted it. The complete &lt;tt&gt;iacore&lt;/tt&gt; function was well over 600 lines long.&lt;/p&gt;
&lt;p&gt;I for one welcome the new standard.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15861274-2499204318775308735?l=oracle-wtf.blogspot.com'/&gt;&lt;/div&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">5</thr:total><feedburner:origLink>http://oracle-wtf.blogspot.com/2007/10/frameworkia.html</feedburner:origLink></item><item><title>What is this "testing" thing?</title><link>http://feedproxy.google.com/~r/blogspot/DVBI/~3/BbkFMmtqCpE/what-is-this-testing-thing.html</link><author>noreply@blogger.com (William Robertson)</author><pubDate>Tue, 14 Aug 2007 10:16:27 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-15861274.post-7521429017992529484</guid><description>&lt;p&gt;&lt;a href="http://forums.oracle.com/forums/thread.jspa?forumID=75&amp;threadID=542567"&gt;Recently asked&lt;/a&gt; on the OTN PL/SQL forum:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;I am reading a book: Learning Oracle PL/SQL by Bill Pribyl and Steven Feuerstein.&lt;/p&gt;&lt;p&gt;I am a newbie of PL/SQL and I got no other programming XPs. but in the very first of this book they are introducing something called: testing, to make some test programms /utilites.&lt;/p&gt;&lt;p&gt;I found that is very hard to make, is it neccessary?&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Apparently, after you've typed the final semicolon, you can either sit back and open a beer with the satisfaction of a job well done, or you can check whether the thing works. And apparently it's hard, so, do we really have to?&lt;/p&gt;&lt;p&gt;Well, another poster was recently arguing that &lt;a href="http://forums.oracle.com/forums/thread.jspa?messageID=1881571#1881571"&gt;PL/SQL is not suited to unit testing anyway&lt;/a&gt;, or refactoring either for that matter, because &lt;i&gt;it isn't object oriented&lt;/i&gt;. I think that will be my excuse from now on. You want me to test stuff, go make PL/SQL more objecty.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15861274-7521429017992529484?l=oracle-wtf.blogspot.com'/&gt;&lt;/div&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">9</thr:total><feedburner:origLink>http://oracle-wtf.blogspot.com/2007/08/what-is-this-testing-thing.html</feedburner:origLink></item><item><title>Welcome back</title><link>http://feedproxy.google.com/~r/blogspot/DVBI/~3/9oTKzDADQz8/welcome-back.html</link><author>noreply@blogger.com (William Robertson)</author><pubDate>Fri, 10 Aug 2007 05:47:25 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-15861274.post-1091133067457129331</guid><description>&lt;p&gt;Our guest administrator "Splogger" has now left the building, along with his page of helpful links to items on Amazon.com and a range of gentlemen's health products.&lt;/p&gt;&lt;p&gt;Suspiciously, a couple of days before he arrived we were taken off air by Blogger's spambots, presumably alerted by the amount of &lt;a href="http://radiofreetooting.blogspot.com/2007/07/roy-batty-writes.html"&gt;irrelevant, repetitive, and nonsensical text&lt;/a&gt; and links to Viagra sites they found here. &lt;a href="http://bloggerstatusforreal.blogspot.com/2006/07/stolen-computers.html"&gt;From what I read&lt;/a&gt;, it seems possible that the Blogger automated suspension to prevent blog spam might have actually left the account vulnerable to blog spammers. As ironies go, that is up there with rain on your wedding day and good advice that you just didn't take.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15861274-1091133067457129331?l=oracle-wtf.blogspot.com'/&gt;&lt;/div&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">9</thr:total><feedburner:origLink>http://oracle-wtf.blogspot.com/2007/08/welcome-back.html</feedburner:origLink></item><item><title>One liner</title><link>http://feedproxy.google.com/~r/blogspot/DVBI/~3/TiRnbPH2P4o/one-liner.html</link><author>noreply@blogger.com (3360)</author><pubDate>Wed, 02 May 2007 18:05:28 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-15861274.post-2576207396364451697</guid><description>&lt;br&gt;I was untangling a query when I came across eight variations of this code where only the literals 'a' to 'e' changed. Two of these were nested within an additional &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_0"&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_0"&gt;NVL&lt;/span&gt;&lt;/span&gt; so that the second would execute if the first returned null.

&lt;pre&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_1"&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_1"&gt;nvl&lt;/span&gt;&lt;/span&gt;(decode(2, 1, 'a', 2, 'b', 3, 'c', 4, 'd', 5, 'e', ' '), '&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_2"&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_2"&gt;na&lt;/span&gt;&lt;/span&gt;')
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15861274-2576207396364451697?l=oracle-wtf.blogspot.com'/&gt;&lt;/div&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">8</thr:total><feedburner:origLink>http://oracle-wtf.blogspot.com/2007/05/one-liner.html</feedburner:origLink></item><item><title>DATE comparisons: the scenic route</title><link>http://feedproxy.google.com/~r/blogspot/DVBI/~3/CBMLLPk-xVQ/date-comparisons-scenic-route.html</link><author>noreply@blogger.com (William Robertson)</author><pubDate>Sun, 08 Apr 2007 05:39:15 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-15861274.post-8228621318724798864</guid><description>&lt;p&gt;Need to calculate the number of minutes between two dates? Yes, the dull way is to subtract one from the other and multiply by 1440. But why do that, when you can simply convert each date into Julian format by converting it into a string and then back to a date, and converting the resulting date into a Julian string, and (in a separate step) applying &lt;tt&gt;TO_NUMBER&lt;/tt&gt; to the result to get an integer, so that you can simply subtract one from the other and multiply by 1440.&lt;/p&gt;
&lt;p&gt;Except that rounds to the nearest day, so an additional step is to calculate the minutes since midnight for each of the two dates, which you can do by simply converting each date into an 'HH:MI AM' string, then back to a date, then back to an 'SSSSS' string, converting it to a number, dividing by 60 and adding it to the result of the first calculation. I think.&lt;/p&gt;

&lt;p&gt;Anyway, consider the following library of handy date functions our Oracle WTF Easter gift to you, the online development community.&lt;/p&gt;
&lt;pre&gt;CREATE PACKAGE dates_pkg
AS
    FUNCTION julian_date
        ( date_to_convert DATE )
        RETURN NUMBER;

    FUNCTION minutes_since_midnight
        ( timevalue DATE )
        RETURN NUMBER;

    FUNCTION minutes_elapsed
        ( lowdate DATE
        , highdate DATE )
        RETURN NUMBER;

END dates_pkg;
/

CREATE PACKAGE BODY dates_pkg
AS
    FUNCTION julian_date
        ( date_to_convert DATE)
        RETURN NUMBER
    IS
        varch_value VARCHAR (10);
        num_value NUMBER (20);
    BEGIN
        SELECT TO_CHAR
               ( TO_DATE(TO_CHAR(date_to_convert,'MM/DD/YYYY'),'MM/DD/YYYY')
               , 'J')
        INTO   varch_value
        FROM   dual;

        SELECT TO_NUMBER (varch_value)
        INTO   num_value
        FROM   dual;

        RETURN (num_value);
    END julian_date;


    FUNCTION minutes_since_midnight (
        timevalue DATE)
        RETURN NUMBER
    IS
        secs_elapsed NUMBER (20);
        mins_elapsed NUMBER (20);
    BEGIN
        SELECT TO_NUMBER
               ( TO_CHAR(TO_DATE(TO_CHAR(timevalue,'HH:MI AM'),'HH:MI AM')
               , 'SSSSS') )
        INTO   secs_elapsed
        FROM   dual;

        SELECT (secs_elapsed / 60)
        INTO   mins_elapsed
        FROM   dual;

        RETURN (mins_elapsed);
    END minutes_since_midnight;


    FUNCTION minutes_elapsed
        ( lowdate DATE
        , highdate DATE )
        RETURN NUMBER
    IS
        final_number NUMBER (20);
        low_julian NUMBER (20);
        high_julian NUMBER (20);
        num_days NUMBER (20);
        num_minutes NUMBER (20);
        temp_mins NUMBER (20);
        min_low NUMBER (20);
        min_high NUMBER (20);
    BEGIN
        SELECT julian_date (lowdate)
        INTO   low_julian
        FROM   dual;

        SELECT julian_date (highdate)
        INTO   high_julian
        FROM   dual;

        SELECT (high_julian - low_julian)
        INTO   num_days
        FROM   dual;

        SELECT (num_days * 1440)
        INTO   num_minutes
        FROM   dual;

        SELECT minutes_since_midnight (lowdate)
        INTO   min_low
        FROM   dual;

        SELECT minutes_since_midnight (highdate)
        INTO   min_high
        FROM   dual;

        SELECT (min_high - min_low)
        INTO   temp_mins
        FROM   dual;

        SELECT (num_minutes + temp_mins)
        INTO   final_number
        FROM   dual;

        RETURN (final_number);

    END minutes_elapsed;
END dates_pkg;
&lt;/pre&gt;
&lt;p&gt;Just for fun, let's test it:&lt;/p&gt;
&lt;pre&gt;CREATE TABLE wtf_test (start_date NOT NULL, end_date NOT NULL) AS
SELECT DATE '2006-12-25' + DBMS_RANDOM.VALUE(1,365)
     , DATE '2007-12-25' + DBMS_RANDOM.VALUE(1,365)
FROM   dual CONNECT BY LEVEL &lt;= 1000;

-- &lt;i&gt;...several runs here to allow for caching etc, last set of results shown...&lt;/i&gt;

SQL&gt; set timing on autotrace traceonly stat

SQL&gt; SELECT dates_pkg.minutes_elapsed(start_date,end_date) FROM wtf_test;

1000 rows selected.

Elapsed: 00:00:03.96

Statistics
----------------------------------------------------------
  &lt;b&gt;16000  recursive calls&lt;/b&gt;
      0  db block gets
     74  consistent gets
      0  physical reads
      0  redo size
   9330  bytes sent via SQL*Net to client
    809  bytes received via SQL*Net from client
     68  SQL*Net roundtrips to/from client
      0  sorts (memory)
      0  sorts (disk)
   1000  rows processed

SQL&gt; SELECT (end_date - start_date) * 1440 FROM wtf_test;

1000 rows selected.

Elapsed: 00:00:00.16

Statistics
----------------------------------------------------------
      &lt;b&gt;0  recursive calls&lt;/b&gt;
      0  db block gets
     74  consistent gets
      0  physical reads
      0  redo size
  25485  bytes sent via SQL*Net to client
    809  bytes received via SQL*Net from client
     68  SQL*Net roundtrips to/from client
      0  sorts (memory)
      0  sorts (disk)
   1000  rows processed&lt;/pre&gt;
&lt;p&gt;So the handy package version takes &lt;b&gt;25 times&lt;/b&gt; as long as the 1-line SQL version.&lt;/p&gt;
&lt;p&gt;And in the interests of fairness, in case you're thinking perhaps that is just the normal overhead of calling PL/SQL functions in SQL, let's try our own function:&lt;/p&gt;
&lt;pre&gt;CREATE FUNCTION minutes_elapsed
    ( lowdate DATE
    , highdate DATE )
    RETURN NUMBER
AS
BEGIN
    RETURN (highdate - lowdate) * 1440;
END minutes_elapsed;
/

SQL&gt; SELECT minutes_elapsed(start_date,end_date) FROM wtf_test;

1000 rows selected.

Elapsed: 00:00:00.26

Statistics
----------------------------------------------------------
     21  recursive calls
      0  db block gets
    107  consistent gets
      0  physical reads
      0  redo size
  25496  bytes sent via SQL*Net to client
    809  bytes received via SQL*Net from client
     68  SQL*Net roundtrips to/from client
      0  sorts (memory)
      0  sorts (disk)
   1000  rows processed&lt;/pre&gt;
&lt;p&gt;Still 15 times faster.&lt;/p&gt;
&lt;p&gt;Many thanks to Padders for sharing this one.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15861274-8228621318724798864?l=oracle-wtf.blogspot.com'/&gt;&lt;/div&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">3</thr:total><feedburner:origLink>http://oracle-wtf.blogspot.com/2007/04/date-comparisons-scenic-route.html</feedburner:origLink></item><item><title>Quote For The Day</title><link>http://feedproxy.google.com/~r/blogspot/DVBI/~3/VWeoQglhYIU/quote-for-day.html</link><author>noreply@blogger.com (William Robertson)</author><pubDate>Fri, 23 Mar 2007 01:11:55 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-15861274.post-7269800696104288291</guid><description>&lt;blockquote&gt;&lt;i&gt;"PL/SQL development can be a tedious and time-consuming job – often monopolizing the valuable time and efforts of Oracle developers."&lt;/i&gt; &lt;b&gt;- &lt;a href="http://www.quest.com/sql_navigator/" rel=nofollow&gt;SQL Navigator page, Quest Software&lt;/a&gt;&lt;/b&gt;&lt;/blockquote&gt;

&lt;p&gt;Spare a thought today for PL/SQL developers, having their precious time tediously monopolised by, umm, PL/SQL development.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15861274-7269800696104288291?l=oracle-wtf.blogspot.com'/&gt;&lt;/div&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">8</thr:total><feedburner:origLink>http://oracle-wtf.blogspot.com/2007/03/quote-for-day.html</feedburner:origLink></item><item><title>423,551 Invalid Indexes</title><link>http://feedproxy.google.com/~r/blogspot/DVBI/~3/-N-uvCkK1bU/423551-invalid-indexes.html</link><author>noreply@blogger.com (William Robertson)</author><pubDate>Mon, 19 Mar 2007 13:56:36 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-15861274.post-2062963565245353794</guid><description>&lt;p&gt;A friend received an alarming email from a commendably proactive DBA who was concerned that he had discovered a potentially serious performance issue on the production system:&lt;/p&gt;
&lt;blockquote&gt;The following result shows there are many invalid  indexes. For example, in the first row we see that there are nearly 423551 invalid indexes for just one row of a table. So if we rebuilt the index it would improve the performance.&lt;/blockquote&gt;
&lt;p&gt;Wow, that sure is a lot of invalid indexes for just one row of a table. For the sake of anonymity, I've run his query against the SCOTT/TIGER schema, where fortunately there are only 14 invalid indexes (or perhaps 10, if that's how you count them). Perhaps you can see what the problem might be:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;SELECT DISTINCT
       t.table_name
     , i.index_name
     , t.num_rows table_rows
     , i.num_rows index_rows
FROM   dba_tables t
     , dba_indexes i
WHERE  t.table_name = 'DEPT'
AND    t.owner = 'SCOTT'
AND    i.owner = t.owner
AND    i.index_type = 'NORMAL';

TABLE_NAME                     INDEX_NAME                     TABLE_ROWS INDEX_ROWS
------------------------------ ------------------------------ ---------- ----------
DEPT                           PK_EMP                                  4         14
DEPT                           EMP_DEPT_IX                             4         14
DEPT                           PK_DEPT                                 4          4
DEPT                           PK_SALGRADE                             4          5

4 rows selected.&lt;/pre&gt;&lt;/blockquote&gt;
&lt;p&gt;There is worse to come. It's not just DEPT that has invalid indexes. He goes on:&lt;/p&gt;
&lt;blockquote&gt;The following result shows there are many invalid indexes, so if we rebuild the index, it would improve the performance. At the same time from the first and last rows, indexes are not being used, so we need to look into it.&lt;/blockquote&gt;
&lt;blockquote&gt;&lt;pre&gt;TABLE_NAME                     INDEX_NAME                     TABLE_ROWS INDEX_ROWS
------------------------------ ------------------------------ ---------- ----------
SALGRADE                       PK_DEPT                                 5          4
SALGRADE                       PK_EMP                                  5         14
SALGRADE                       EMP_DEPT_IX                             5         14
SALGRADE                       PK_SALGRADE                             5          5

TABLE_NAME                     INDEX_NAME                     TABLE_ROWS INDEX_ROWS
------------------------------ ------------------------------ ---------- ----------
EMP                            PK_DEPT                                14          4
EMP                            PK_EMP                                 14         14
EMP                            EMP_DEPT_IX                            14         14
EMP                            PK_SALGRADE                            14          5&lt;/pre&gt;&lt;/blockquote&gt;
&lt;p&gt;I just can't help wondering what he thinks an index is.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15861274-2062963565245353794?l=oracle-wtf.blogspot.com'/&gt;&lt;/div&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">6</thr:total><feedburner:origLink>http://oracle-wtf.blogspot.com/2007/03/423551-invalid-indexes.html</feedburner:origLink></item><item><title>Performance Tuning and The Big O</title><link>http://feedproxy.google.com/~r/blogspot/DVBI/~3/tCdmN-c90bc/performance-tuning-and-big-o_17.html</link><author>noreply@blogger.com (William Robertson)</author><pubDate>Wed, 17 Jan 2007 08:28:42 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-15861274.post-116899419612369997</guid><description>&lt;p&gt;Oracle Performance Tuning is a big subject, as anyone will appreciate who has read any of a number of books that set out to help you to understand what problem you are trying to solve, what factors may affect the performance you are seeing, what strategies are available to the query optimizer, and so on.&lt;/p&gt;

&lt;p&gt;While Cary Millsap's &lt;i&gt;Optimizing Oracle Performance&lt;/i&gt; focusses on finding, tracing and prioritising specific problems in the face of vague reports that the system seems a bit slow this week, and Jonathan Lewis' &lt;i&gt;Cost-Based Oracle Fundamentals&lt;/i&gt; takes us on a tour of the CBO to help answer such questions as &lt;i&gt;Why isn't my &lt;tt&gt;EXISTS&lt;/tt&gt; query using an index? (and why isn't it faster than the &lt;tt&gt;IN&lt;/tt&gt; version?)&lt;/i&gt; a poster on &lt;a href=http://www.orafaq.com/forum/?t=rview&amp;goto=213972&gt;OraFAQ&lt;/a&gt; has an approach we've not seen before:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The following is a problem I need help with and I am willing to pay for help if necessary. Any info would be greatly appreciated.&lt;/p&gt;

&lt;p&gt;Two tables in a database:&lt;/p&gt;

&lt;p&gt;Table1 contains a list of phone numbers&lt;br&gt;
Table2 contains a list of phone numbers as well&lt;/p&gt;

&lt;p&gt;I would like to create a Table3, in which Table3 contains all numbers
from Table1 that is not in Table2. I am looking for the shortest
runtime possible, keeping in mind that you can use whatever method(s)
you deem necessary.&lt;/p&gt;

&lt;p&gt;Table1 contains 30 Million rows,&lt;br&gt;
Table2 contains 2000 rows.&lt;/p&gt;

&lt;p&gt;given a regular SQL expression, it will yield Big O(m*n)&lt;/p&gt;

&lt;p&gt;Where m = rowcount of Table1&lt;br&gt;
and n = rowcount of Table2&lt;/p&gt;

&lt;p&gt;Generate for me, a method in which, runtime will yield Big O (m log2
n).&lt;/p&gt;

&lt;p&gt;I don't need code, I want to hear your logic. Table1 is customers, Table2 is a list of prepaid phone numbers. Table3 is list of people to bill.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;As usual no database version is given. The first suggestion, as you might expect, is the quite reasonable:&lt;/p&gt;
&lt;pre&gt;select phone_no from table1
minus
select phone_no from table2;&lt;/pre&gt;
&lt;p&gt;accompanied by a comment that it doesn't seem like a great piece of schema design to have two tables in the first place. However, the reply comes back:&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;The guy who wrote this problem just told me that this answer is incorrect.&lt;/p&gt;
&lt;p&gt;His response to me was:&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;it's not too simplistic, but it is incorrect. This will still yield a big O(m*n).&lt;/p&gt;

&lt;p&gt;Give it one more try, you are thinking too much in terms of DB.&lt;/p&gt;

&lt;p&gt;Ask yourself, what are the only structures that would yield
BigO(nlog2n)? Answer that, and you will get your answer.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;Any ideas?&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;Resident mathematician Ross Leishman tried to explain to me what &lt;i&gt;Big O (m log2n)&lt;/i&gt; means, and I can confirm that it is not after all a &lt;i&gt;When Harry Met Sally&lt;/i&gt; reference as most of us would probably assume. Apparently the version with an &lt;tt&gt;EXISTS&lt;/tt&gt; subquery was what was wanted, which seemed odd to me on a number of levels, not least that an &lt;tt&gt;IN&lt;/tt&gt; subquery would probably produce the same plan, especially in 10g where the new &lt;tt&gt;HASH JOIN RIGHT ANTI&lt;/tt&gt; allows the database to build its hash table from the 2,000-row table2 rather than the 30 million-row table1. But of course we don't know the database version, do we? Or whether the columns are nullable, unique or indexed, or how values are distributed, or really anything about the actual environment that would help in solving a real-world performance problem. I can see where I'm going wrong though. I am thinking too much in terms of DB.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15861274-116899419612369997?l=oracle-wtf.blogspot.com'/&gt;&lt;/div&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">4</thr:total><feedburner:origLink>http://oracle-wtf.blogspot.com/2007/01/performance-tuning-and-big-o_17.html</feedburner:origLink></item><item><title>Short loop</title><link>http://feedproxy.google.com/~r/blogspot/DVBI/~3/iiF7l2LeOj4/short-loop_13.html</link><author>noreply@blogger.com (William Robertson)</author><pubDate>Mon, 15 Jan 2007 07:28:43 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-15861274.post-116870200874889046</guid><description>&lt;p&gt;It's good to see a GOTO every now and then. However, the sender of this one (thanks!) was most impressed by the loop that goes from 1 to &lt;tt&gt;v_totalcntr&lt;/tt&gt;, and indeed the fact that there is a loop and a &lt;tt&gt;v_totalctr&lt;/tt&gt; variable at all, with the variable carefully set from the cursor's &lt;tt&gt;%ROWCOUNT&lt;/tt&gt;, when it can only ever have one value:&lt;/p&gt;
&lt;pre&gt;DECLARE
  CURSOR cur_pricing IS
      SELECT col1, col2
      FROM   sometable;

  var_pricing cur_pricing%ROWTYPE;

BEGIN
  OPEN cur_pricing;
  FETCH cur_pricing INTO var_pricing;

  IF cur_pricing%NOTFOUND THEN
      GOTO continue;
  END IF;

  v_totalcntr := cur_pricing%ROWCOUNT;

  FOR r IN 1..v_totalcntr
  LOOP
      -- loads of stuff here
      -- but no fetch from cur_pricing
      -- not even for the one time this loop will execute :-)
  END LOOP;

  &amp;lt;&amp;lt;continue&gt;&gt;
  NULL;
END;&lt;/pre&gt;
&lt;p&gt;Of course you could just fetch the value you want and process it, but where would be the fun in that?&lt;/p&gt;

&lt;p&gt;&lt;b&gt;PS&lt;/b&gt; The person who sent this in emailed me with a point I must admit hadn't occurred to me:&lt;/p&gt;

&lt;blockquote&gt;Saw you posted this one - thanks. But did you pick up on what they probably thought they were doing? I think whoever wrote it thought that &lt;tt&gt;%rowcount&lt;/tt&gt; would have the TOTAL number of rows that the cursor would return - so they thought they would be looping around ALL the records in the cursor. The fact that they also forgot to fetch again in the loop just adds to the problem of course.&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15861274-116870200874889046?l=oracle-wtf.blogspot.com'/&gt;&lt;/div&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">4</thr:total><feedburner:origLink>http://oracle-wtf.blogspot.com/2007/01/short-loop_13.html</feedburner:origLink></item><item><title>Code Re-use</title><link>http://feedproxy.google.com/~r/blogspot/DVBI/~3/tsnNVJ472y8/code-re-use.html</link><author>noreply@blogger.com (William Robertson)</author><pubDate>Wed, 13 Dec 2006 17:24:09 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-15861274.post-116603248419013315</guid><description>&lt;p&gt;This code was anonymised by the sender and some of the original logic may be a bit harder to make sense of as a result. Instead of EMP records, you should probably imagine it checking billion-dollar financial deals or nuclear reactor core temperature readings. Anyway, I think I've figured out what it's supposed to do.&lt;/p&gt;

&lt;p&gt;You pass in an EMP record containing &lt;i&gt;first name, last name, email address&lt;/i&gt; and so on, and it calls &lt;tt&gt;OTHER_PROC(email_address,&amp;nbsp;the_emp_record_as_passed_in)&lt;/tt&gt; - &lt;i&gt;but only if&lt;/i&gt; the email address is not null, &lt;i&gt;and&lt;/i&gt; it is unique for employees with that name. For some reason. But how to check? Simple:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use a cursor to load all the rows for that name into an array. (Apparently there were 130+ columns in the original table.)&lt;/li&gt;
&lt;li&gt;Check array.COUNT to see how many rows there are.&lt;/li&gt;
&lt;li&gt;If there is only one row, use it, taking care to use an NVL expression because we definitely don't want a NULL email address.&lt;/li&gt;
&lt;li&gt;If there is more than one row, open the same cursor again, and this time loop through it comparing each row's email address with the previous one. If it's the same, set &lt;tt&gt;lv_email_same&lt;/tt&gt; = 1, otherwise set it to 0. That way, at the end of the loop we'll know whether they were all the same or not, right?&lt;/li&gt;
&lt;/ol&gt;
&lt;br&gt;
&lt;pre&gt;
PROCEDURE unleash_havoc (p_emp_rec emp%rowtype)
IS
   lv_email_same  NUMBER(1) :=0; -- 0: no, 1: yes
   lv_email_null  NUMBER(1) :=0; -- 0: no, 1: yes
   lv_email       emp.email%TYPE := NULL;
   ln_row         NUMBER;

   TYPE emp_tab IS TABLE OF emp%ROWTYPE;
   lt_emp_data  emp_tab;

   CURSOR c_emp (p_last_name VARCHAR2, p_first_name VARCHAR2) IS
      SELECT *
      FROM   emp e
      WHERE  e.last_name = p_last_name
      AND    e.first_name = p_first_name;

BEGIN
   OPEN c_emp (p_emp_rec.last_name, p_emp_rec.first_name);
   FETCH c_emp BULK COLLECT INTO lt_emp_data;
   CLOSE c_emp;

   IF lt_emp_data.COUNT = 1 THEN
       ln_row := lt_emp_data.FIRST;
       lv_email  := NVL(lt_emp_data(ln_row).email,NULL);
       other_proc(lv_email,p_emp_rec);

   ELSIF lt_emp_data.COUNT &gt; 1 THEN

       FOR r IN c_emp (p_emp_rec.last_name, p_emp_rec.first_name) LOOP
           IF NVL(r.email,'X') = NVL(lv_email,'X') THEN
               lv_email := r.email;
               lv_email_same := 1;
           ELSE
               lv_email := r.email;
               lv_email_same := 0;
           END IF;

           IF r.email IS NULL THEN
               lv_email_null := 1;
           ELSE
               lv_email_null := 0;
           END IF;
       END LOOP;

       IF  lv_email_same = 1
       AND lv_email_null = 0
       THEN
           lv_email  := NVL(lt_emp_data(ln_row).email,NULL);
           other_proc(lv_email,p_emp_rec);
       ELSE
           ...
       END IF;
   END IF;
END;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15861274-116603248419013315?l=oracle-wtf.blogspot.com'/&gt;&lt;/div&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">6</thr:total><feedburner:origLink>http://oracle-wtf.blogspot.com/2006/12/code-re-use.html</feedburner:origLink></item><item><title>Pause For Thought part 2</title><link>http://feedproxy.google.com/~r/blogspot/DVBI/~3/hJtytfRUeeQ/pause-for-thought-part-2.html</link><author>noreply@blogger.com (William Robertson)</author><pubDate>Wed, 18 Oct 2006 23:58:56 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-15861274.post-116124106163866933</guid><description>&lt;p&gt;In &lt;a href="http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:4243161825986#74632859512796"&gt;an AskTom thread about native compilation&lt;/a&gt;, a poster mentions that he is seeing some big CPU waits on his system and wonders whether native compilation would help. After some discussion of tracing and profiling and his 32 Tuxedo connections, he reports back that from talking to the programmer (possibly &lt;a href="http://oracle-wtf.blogspot.com/2006/07/pause-for-thought.html"&gt;this guy&lt;/a&gt;), he might have narrowed the problem down to a procedure called DELAY():&lt;/p&gt;
&lt;blockquote&gt;I just happened to talk to the programmer and what i understand is that that 
specific function when called so many times , it is internally calling a 
procedure with passing a value n, where n is like 4,5,6 etv.
That procedure is called delay and its job is to create a delay in the logic 
flow. So the delay procedure accepsts values like 10 as seconds and then it
&lt;pre&gt;FOR di IN 1..sed LOOP
   NULL;
END LOOP;&lt;/pre&gt;
A random thought, could this when run so many times accumulate huge cpu?&lt;/blockquote&gt;
&lt;p&gt;Tom thinks maybe it might.&lt;/p&gt;
&lt;p&gt;Thanks Tom for sending this in.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15861274-116124106163866933?l=oracle-wtf.blogspot.com'/&gt;&lt;/div&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">7</thr:total><feedburner:origLink>http://oracle-wtf.blogspot.com/2006/10/pause-for-thought-part-2.html</feedburner:origLink></item><item><title>Death By Furniture</title><link>http://feedproxy.google.com/~r/blogspot/DVBI/~3/7c2vYuXfPXo/death-by-furniture_12.html</link><author>noreply@blogger.com (William Robertson)</author><pubDate>Thu, 12 Oct 2006 15:27:24 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-15861274.post-116069195206233672</guid><description>&lt;p&gt;According to &lt;a href="http://www.identifiers.org" rel="nofollow"&gt;www.identifiers.org&lt;/a&gt;, there are two classes of relational database: &lt;i&gt;"Code Class"&lt;/i&gt; and &lt;i&gt;"Identifier Class"&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;We hadn't heard of those either, but it's all made clear in &lt;a href="http://www.identifiers.org/downloads/05_99.pdf" rel="nofollow"&gt;this presentation&lt;/a&gt; (pdf, 1.2MB), in which the limitations of the conventional approach and a novel approach to schema design are explained without the aid of Powerpoint, in a series of pictures like this one:&lt;/p&gt;
&lt;div style="margin: 15pt 0pt; clear: left;"&gt;&lt;img src="http://photos1.blogger.com/blogger/7758/1483/1600/george-explains-airpii.jpg" /&gt;&lt;/div&gt;
&lt;p&gt;Still confused? Never mind, you can follow the debate on &lt;a href="http://forums.oracle.com/forums/thread.jspa?threadID=427362"&gt;this OTN thread&lt;/a&gt;, which George begins by asking for a simple clarification regarding the capabilities of the Oracle RDBMS. From the answers to this, he should be able to determine whether Oracle is old-hat &lt;i&gt;Code Class&lt;/i&gt; or funky new &lt;i&gt;Identifier Class&lt;/i&gt;:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;I have an interest in establishing how the Oracle System Catalogues cope with particular changes. I have never used Oracle, but I have carried out the same test on another RDBMS. If I had access to Oracle I would have carried out this test myself.&lt;/p&gt;
&lt;p&gt;The test goes as follows.&lt;/p&gt;
&lt;p&gt;Create a new database.&lt;/p&gt;
&lt;p&gt;Create a new simple table, with just a few columns.&lt;/p&gt;
&lt;p&gt;Create a form for the table, and add a few rows.&lt;/p&gt;
&lt;p&gt;Rename the table or a column – if you can’t, then the RDBMS is Code Class.&lt;/p&gt;
&lt;p&gt;If you can rename the table or a column, then do so, and invoke the form that you used before changing the table or column name. If it doesn’t work, the RDBMS is Code Class; if it does then the RDBMS is Identifier Class.&lt;/p&gt;
&lt;p&gt;In an Identifier Class RDBMS changes of column or relation/table name will not interfere with the operation of any form already in place based on that table.&lt;/p&gt;
&lt;p&gt;I'll be very grateful if anybody can give me a definitive answer on this, either through already having explored the issue or by running the test.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;It turns out that &lt;i&gt;"Code Class"&lt;/i&gt; covers all existing RDBMS products ever conceived, and &lt;i&gt;"Identifier Class"&lt;/i&gt; is an improved model invented by George himself, in which some theoretical 4GL development tool yet to be designed allows you to change table and column names without breaking existing code or having to define a view, and surrogate keys are, well, pretty much the same except that they are now called &lt;i&gt;attribute independent relative position independent identifiers&lt;/i&gt;. Perhaps one day Oracle will advance to this point, especially now that they've fixed DBMS_OUTPUT and must be wondering what to do next (perhaps after getting a product to work on Apple Mac and fixing the OTN "change password" facility). We can but dream.
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15861274-116069195206233672?l=oracle-wtf.blogspot.com'/&gt;&lt;/div&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">18</thr:total><feedburner:origLink>http://oracle-wtf.blogspot.com/2006/10/death-by-furniture_12.html</feedburner:origLink></item><item><title>Useful books</title><link>http://feedproxy.google.com/~r/blogspot/DVBI/~3/hnG2a4QHbQU/useful-books.html</link><author>noreply@blogger.com (William Robertson)</author><pubDate>Sat, 16 Sep 2006 15:27:19 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-15861274.post-115840843719502848</guid><description>&lt;div style="margin: 15pt 0pt; clear: left;"&gt;&lt;img src="http://photos1.blogger.com/blogger/7758/1483/400/spider-safari-1.jpg" border="0" /&gt;
&lt;p&gt;An enormous spider appears. It's clearly coming for you. Or not. What do you do?&lt;/p&gt;&lt;/div&gt;

&lt;div style="margin: 15pt 0pt; clear: left;"&gt;&lt;img src="http://photos1.blogger.com/blogger/7758/1483/400/spider-safari-2.jpg" border="0" /&gt;
&lt;p&gt;Staying calm, place a glass or similar containment device over the creature.&lt;/p&gt;&lt;/div&gt;

&lt;div style="margin: 15pt 0pt; clear: left;"&gt;&lt;img src="http://photos1.blogger.com/blogger/7758/1483/400/spider-safari-3.jpg" alt="" border="0" /&gt;
&lt;p&gt;Now gently slide a card under the glass, taking care not to trap any legs. There should be eight after you have completed this manoeuvre.&lt;/p&gt;&lt;/div&gt;

&lt;div style="margin: 15pt 0pt; clear: left;"&gt;&lt;img src="http://photos1.blogger.com/blogger/7758/1483/400/spider-safari-4.jpg" border="0" /&gt;
&lt;p&gt;Transfer to a suitable platform such as a book, and carry to a window or other suitable release location.&lt;/p&gt;&lt;/div&gt;

&lt;div style="margin: 15pt 0pt; clear: left;"&gt;&lt;img src="http://photos1.blogger.com/blogger/7758/1483/400/spider-safari-5.jpg" border="0" /&gt;
&lt;p&gt;No Oracle experts were harmed in the making of this blog.&lt;/p&gt;&lt;/div&gt;

&lt;div style="margin: 15pt 0pt; clear: left;"&gt;&lt;img src="http://photos1.blogger.com/blogger/7758/1483/400/spider-safari-6.jpg" border="0" /&gt;
&lt;p&gt;Reintroduce the creature into the wild, where it can begin a new life free to roam among its own kind. Or just wander back in of course, but spiders are not known for their homing instinct. Or are they? To be honest we haven't checked. This one said something about "Scotland" and "revenge".&lt;/p&gt;
&lt;/div&gt;

&lt;div style="margin: 15pt 0pt; clear: left;"&gt;&lt;img style="" src="http://photos1.blogger.com/blogger/7758/1483/400/spider-safari-7.jpg" border="0" /&gt;
&lt;p&gt;Finally, always sterilise your equipment.&lt;/p&gt;&lt;/div&gt;

&lt;div style="margin: 15pt 0pt; clear: left;"&gt;&lt;a href="http://oracledoug.com/serendipity/index.php?/archives/1074-Useful-Books.html" rel="nofollow"&gt;&lt;img src="http://photos1.blogger.com/blogger/7758/1483/320/crimescene.jpg" border="0" /&gt;&lt;/a&gt;
&lt;p&gt;Meanwhile in Edinburgh, police were called to a flat in the Stockbridge area following reports of a violent assault...&lt;/p&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15861274-115840843719502848?l=oracle-wtf.blogspot.com'/&gt;&lt;/div&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">16</thr:total><feedburner:origLink>http://oracle-wtf.blogspot.com/2006/09/useful-books.html</feedburner:origLink></item><item><title>Just, Why?</title><link>http://feedproxy.google.com/~r/blogspot/DVBI/~3/jUof6pJoDNw/just-why.html</link><author>noreply@blogger.com (Thai Rices)</author><pubDate>Wed, 13 Sep 2006 04:44:00 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-15861274.post-115814784058633218</guid><description>I'm currently debugging a procedure of the form illustrated below, lovingly recreated using the ubiquitous scott.emp table.

I'm also taking suggestions on what might've been going through the head of the person who wrote it.

&lt;pre&gt;

RENAME emp TO emp_table
/
CREATE OR REPLACE VIEW emp
AS
   SELECT *
     FROM emp_table
/
CREATE OR REPLACE TRIGGER mod_emp
   INSTEAD OF UPDATE
   ON emp
   FOR EACH ROW
DECLARE
   new_emp                       emp_table%ROWTYPE;
   old_emp                       emp_table%ROWTYPE;
BEGIN
   new_emp.empno       := :NEW.empno;
   new_emp.ename       := :NEW.ename;
   new_emp.job         := :NEW.job;
   new_emp.mgr         := :NEW.mgr;
   new_emp.hiredate    := :NEW.hiredate;
   new_emp.sal         := :NEW.sal;
   new_emp.comm        := :NEW.comm;
   new_emp.deptno      := :NEW.deptno;
   old_emp.empno       := :OLD.empno;
   old_emp.ename       := :OLD.ename;
   old_emp.job         := :OLD.job;
   old_emp.mgr         := :OLD.mgr;
   old_emp.hiredate    := :OLD.hiredate;
   old_emp.sal         := :OLD.sal;
   old_emp.comm        := :OLD.comm;
   old_emp.deptno      := :OLD.deptno;
   update_emp (old_emp, new_emp);
END;
/

CREATE OR REPLACE PROCEDURE update_emp (
   old_emp                             emp_table%ROWTYPE
  ,new_emp                             emp_table%ROWTYPE
)
IS
BEGIN
   IF old_emp.empno != new_emp.empno
   THEN
      RETURN;   --can't update primary key attribute
   END IF;

   IF     old_emp.empno IS NOT NULL
      AND new_emp.empno IS NULL
   THEN
      DELETE FROM emp_table
            WHERE empno = old_emp.empno;

      RETURN;
   END IF;

   IF    (    old_emp.ename IS NULL
          AND new_emp.ename IS NOT NULL)
      OR (    old_emp.ename IS NOT NULL
          AND new_emp.ename != old_emp.ename)
   THEN
      UPDATE emp_table
         SET ename = new_emp.ename
       WHERE empno = old_emp.empno;
   END IF;
   -- ..
   -- ..
   -- ..
   IF    (    old_emp.deptno IS NULL
          AND new_emp.deptno IS NOT NULL)
      OR (    old_emp.deptno IS NOT NULL
          AND new_emp.deptno != old_emp.deptno)
   THEN
      UPDATE emp_table
         SET deptno = new_emp.deptno
       WHERE empno = old_emp.empno;
   END IF;
END;
/

&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15861274-115814784058633218?l=oracle-wtf.blogspot.com'/&gt;&lt;/div&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">14</thr:total><feedburner:origLink>http://oracle-wtf.blogspot.com/2006/09/just-why.html</feedburner:origLink></item><item><title>A Year of WTFs</title><link>http://feedproxy.google.com/~r/blogspot/DVBI/~3/WJ-DBMscFss/year-of-wtfs_09.html</link><author>noreply@blogger.com (William Robertson)</author><pubDate>Sat, 09 Sep 2006 08:22:43 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-15861274.post-115780635282442626</guid><description>&lt;p&gt;Each year, the Oracle WTF organisation celebrates its anniversary by inviting a fellow Oracle professional to share an evening of fine Eastern European lager and disappointing bar snacks in a   pub where you can't hear each other properly, and this year it was the turn of former newbie (but now of course senior expert) DBA &lt;a href="http://newbiedba.blogspot.com"&gt;Lisa Dobson&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Actually that's not quite true - I realised today it was just over a year ago that we started the blog, and the other evening some of us met up with Lisa who happened to be in town, and if I'd thought of this a bit earlier I could probably have pretended it was all planned. Anyway it was nice meeting Lisa, and we enjoyed the story about the colleague who accidentally deleted &lt;i&gt;the entire production server&lt;/i&gt;, as luck would have it a week after the server room air conditioning took out the only other server by dripping a surprisingly large amount of water into it. That rather outdid my story about the day we turned up for work at a client's site and found nobody could log in, because as it happened someone had stolen the servers during the night. Or the other one, if I'd remembered to tell it, about the high street retail chain whose backup system involved a PC and a timer plug. (I shouldn't laugh - it actually worked quite well.) It was also reassuring to hear we are not the only ones who don't understand a single bloody word of those "Oracle" blogs about installing a Java framework in JDeveloper to implement service-oriented BPEL with a right-click and some XML. Umm, neat.&lt;/p&gt;&lt;p&gt;It seems we're also not the only ones to have been shocked and saddened by &lt;a href="http://oracledoug.com/serendipity/index.php?/archives/1074-Useful-Books.html"&gt;Doug Burns' recent senseless killing spree&lt;/a&gt;. This monster must be stopped. (...is probably what Doug said as he reached for his copy of "Expert One-On-One Oracle").&lt;/p&gt;
&lt;p&gt;Anyway, one year, 63 posts, and some lessons learned:&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;Post one of Tom Kyte's pet hates like &lt;tt&gt;WHEN OTHERS THEN NULL&lt;/tt&gt; (or &lt;a href="http://www.datawebtect.com/wordpress/2006/08/22/when-others/"&gt;&lt;tt&gt;WHEN OTHERS THEN DBMS_OUTPUT&lt;/tt&gt;&lt;/a&gt;, which isn't much better quite frankly) for a mention on &lt;a href="http://tkyte.blogspot.com/2006/08/ouch-that-hurts.html"&gt;his blog&lt;/a&gt; and a surefire thousand hits. We need one about &lt;a href="http://tkyte.blogspot.com/2006/01/im-speak.html"&gt;IM Speak&lt;/a&gt; now b/c im sure u will C loadsa hits ;-)&lt;/li&gt;
&lt;li&gt;Post something involving security for a mention on &lt;a href="http://www.petefinnigan.com/weblog/archives/00000765.htm"&gt;Pete Finnigan's site&lt;/a&gt;. We also get a steady stream of visitors googling for &lt;i&gt;"forgot system password +oracle"&lt;/i&gt;, &lt;i&gt;"how to get password of a user in oracle"&lt;/i&gt; and so on, and being directed to &lt;a href="http://oracle-wtf.blogspot.com/2006/03/umm-i-forgot-my-password-part-2.html"&gt;Umm, I Forgot My Password, part 2&lt;/a&gt;. (In future just &lt;a href="http://thedailywtf.com/forums/thread/85316.aspx"&gt;put it on a Post-It under your keyboard&lt;/a&gt; like everyone else.)&lt;/li&gt;
&lt;li&gt;Titles involving common Oracle error codes seem to do well. A lot of visitors come here from  a Google search for &lt;a href="http://www.google.com/search?q=sp2-0552" hl="en&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;q=SP2-0552&amp;btnG=Google%20Search&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;quot;"&gt;SP2-0552&lt;/a&gt; (guys, you have a variable with a colon in front of it somewhere). We need some posts about ORA-0600 or TNSNAMES.&lt;/li&gt;
&lt;li&gt;A lot of people seem to be searching for an explanation of joins and end up at our &lt;a href="http://oracle-wtf.blogspot.com/2005/09/joins-explained.html"&gt;Joins Explained&lt;/a&gt;, heaven help them, where a Mr Sanders Kaufman explains things like &lt;i&gt;"Left Joins are joined on the left columns of two tables. Right Joins are joined on the right columns of two tables."&lt;/i&gt; I'm glad we got that cleared up.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.google.com/analytics/"&gt;Google Analytics&lt;/a&gt; Rock. So (while we're at it) do &lt;a href="http://www.statcounter.com/"&gt;Statcounter&lt;/a&gt;, &lt;a href="http://www.feedburner.com"&gt;Feedburner&lt;/a&gt; and &lt;a href="http://www.cocomment.com/"&gt;CoComment&lt;/a&gt;.
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;We were recently offered some sponsorship by price comparison website &lt;a href="http://www.shopzilla.co.uk"&gt;Shopzilla&lt;/a&gt; (or rather, they emailed me a week ago and I remembered it in the pub). The consensus among those present was that we should not accept it, although personally I think all that would change if we could get &lt;a href="http://thedailywtf.com/forums/thread/87772.aspx"&gt;The Daily WTF's Beanbag Girl&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;We were also kindly offered a spot on &lt;a href="http://www.pythian.com/blogs/about-log-buffer/"&gt;Pythian Group's Logfile Of The Vanities&lt;/a&gt; or whatever it's called (or rather, they emailed me a month ago and I seem to have deleted the message, sorry guys, meant to get back to you) but  I didn't take them up on it, partly because there didn't seem much point in writing a piece telling people about Oracle blogs they already read (surely?) via &lt;a href="http://blogs.oracle.com/"&gt;blogs.oracle.com&lt;/a&gt;, and also because it's explicitly for DBAs, and with the possible exception of Padders we are all developers (even though these days "developer" is often assumed to mean someone who is into aspect-oriented JDeveloper BPEL plug-ins). Our main thing is SQL, PL/SQL and &lt;a href="http://oracle-wtf.blogspot.com/2006/02/eav-returns-concrete-elephant-approach.html"&gt;data modelling&lt;/a&gt;, and AFAIK none of those have much to do with the DBA role. In fact, thinking about it I'm not sure why they asked. And is that &lt;tt&gt;Pie-thian&lt;/tt&gt; as in Pythagoras and Python, or &lt;tt&gt;Pith-ian&lt;/tt&gt; as in &lt;a href="http://www.hp-lexicon.org/hogwarts/houses/gryffindor.html"&gt;Gryffindor&lt;/a&gt; and &lt;a href="http://www.hp-lexicon.org/hogwarts/houses/slytherin.html"&gt;Slytherin&lt;/a&gt;, anyway?&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15861274-115780635282442626?l=oracle-wtf.blogspot.com'/&gt;&lt;/div&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">32</thr:total><feedburner:origLink>http://oracle-wtf.blogspot.com/2006/09/year-of-wtfs_09.html</feedburner:origLink></item></channel></rss>
