Re: How to exit from pl/sql

From: malcolm <malcolmarnold_at_gmail.com>
Date: Wed, 30 Jan 2008 09:39:31 -0800 (PST)
Message-ID: <51635434-7e2a-42d2-9fac-756a1b964979@1g2000hsl.googlegroups.com>


On Jan 30, 5:01 pm, wagen..._at_yahoo.com wrote:
> Thanks David for responding.
>
> 500 is just a test number. What we are trying to do:
>
> - we have a table that has a high amount of DML all the time (24x7) in
> fact every second
> - at midnight we want to truncate the table. the reason for the pl/sql
> procedure is to get around the ORA-00054 resource busy error.
>
> Your suggestion for select count(*) may not work in this scenario.

Well putting your truncate problems aside, and looking at this as a purely PL/SQL question...

If the truncate is not successful, you can rely on an exception from the server.

Therefore try this:

DECLARE
   str constant VARCHAR2(150) := 'TRUNCATE TABLE t1;    try_again boolean := true;
BEGIN
   while try_again LOOP

        begin
             EXECUTE IMMEDIATE str;
             try_again := false;
        exception
             when others then
                 null;
        end;

   END LOOP;
END;
/

Of course this code is not guaranteed to complete.... Received on Wed Jan 30 2008 - 11:39:31 CST

Original text of this message