Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Why can't I truncate table?

Re: Why can't I truncate table?

From: schong <schong_at_werple.mira.net.au>
Date: Mon, 15 Mar 1999 03:57:44 -0800
Message-ID: <36ECF5B8.7DFE@werple.mira.net.au>


Bill,  

  If you don't mind changing the code that does the insert and truncate   to add some house keeping statments before and after then you can   try using the package dbms_lock.request(...).

  for insert ...

   dbms_lock.allocate_unique('xyz', :lockhandle);
   dbms_lock.request(:lockhandle, 3, maxwait, false); 
   insert ....

  for truncate ...

 1.lock table xyz in exclusive mode;
   dbms_lock.allocate_unique('xyz', :lockhandle);    dbms_lock.request(:lockhandle, 6, maxwait, true);

 2.select 
 3.truncate table xyz
 4.dbms_lock.release(:lockhandle)

 This solution will prevent your session from failing with a nowait  problem.

 BTW, delete does not hold a dictionary lock. Any DDL statements  that requires an exclusive DDL lock will wait on any type of  table lock whether it be DDL or DML.

 Clement

Bill Wine wrote:
>
> I want to lock a table to prevent changes, do some read-only
> processing on rows in the table, then truncate the table,
> and commit, e.g.
>
> 1. lock table xyz in exclusive mode;
> 2. select ... from xyz;
> 3. truncate table xyz;
> 4. commit;
>
> I find (Oracle 7.3.3.4) that if another user attempts to insert
> into xyz after step 1, but before step 3, the truncate fails with:
>
> ORA-00054: resource busy and acquire with NOWAIT specified
>
> The other user's insert then succeeds.
>
> If I 'delete from xyz' instead of 'truncate xyz' it works as expected.
>
> Why can't the process that locks the table in exclusive mode then
> do a truncate when another process is waiting to insert?
>
> Thanks for your help.
>
> Bill
Received on Mon Mar 15 1999 - 05:57:44 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US