Links
Home
Oracle DBA Forum
Frequent Oracle Errors
TNS:could not resolve the connect identifier specified
Backtrace message unwound by exceptions
invalid identifier
PL/SQL compilation error
internal error
missing expression
table or view does not exist
end-of-file on communication channel
TNS:listener unknown in connect descriptor
insufficient privileges
PL/SQL: numeric or value error string
TNS:protocol adapter error
ORACLE not available
target host or object does not exist
invalid number
unable to allocate string bytes of shared memory
resource busy and acquire with NOWAIT specified
error occurred at recursive SQL level string
ORACLE initialization or shutdown in progress
archiver error. Connect internal only, until freed
snapshot too old
unable to extend temp segment by string in tablespace
Credential retrieval failed
missing or invalid option
invalid username/password; logon denied
unable to create INITIAL extent for segment
out of process memory when trying to allocate string bytes
shared memory realm does not exist
cannot insert NULL
TNS:unable to connect to destination
remote database not found'>ora-02019
exception encountered: core dump
inconsistent datatypes
no data found
TNS:operation timed out
PL/SQL: could not find program
existing state of packages has been discarded
maximum number of processes exceeded
error signaled in parallel query server
ORACLE instance terminated. Disconnection forced
TNS:packet writer failure
see ORA-12699
missing right parenthesis
name is already used by an existing object
cannot identify/lock data file
invalid file operation
quoted string not properly terminated
faster way of doing this?

faster way of doing this?

2005-03-23       - By Guang Mei

Reply:     1     2     3     4  

Hi,

The code needs to work on oracle 8i and 9i. The current code occasionally
gave "Ora-01555 (See Ora-01555.ora-code.com): Snapshot too old" error (becuase there is a commit within
the loop for each 1000 rows, which I took out in my test code below).
Assuming we can not change the RBS size, and I found Tom suggested to do the
bulk delete

http://asktom.oracle.com/pls/ask/f?p=4950:8:17490901823893610313::NO::F4950_
P8_DISPLAYID,F4950_P8_CRITERIA:1046580359875

However my test showed the new method ran slower. Is there a better/faster
way of writing the same delete sql? The total number of "to-be-deleted" rows
could be huge in the table, so I need to use rownum<=1000.  TIA.

Guang
-- ---- ---- ------

set timing on
set serveroutput on

-- current method:

declare
   counter             number;
   cursor DelAudit_cur1 is
    SELECT AuditTrail.RID
      FROM   AuditTrail, Customers, Banks, auditedUsers
      WHERE  AuditTrail.UserRID = AuditedUsers.userRID
    AND    auditedUsers.Customerrid = Customers.RID
    AND    Customers.Bank = Banks.RID
    AND    TRUNC(AuditTrail.DateTime) < (TRUNC(SYSDATE) -
NVL(Customers.AUDITRETENTIONPERIOD, Banks.AUDITRETENTIONPERIOD));  
begin
   counter := 0;
   FOR Cur_DelAudit IN DelAudit_cur1 LOOP
     DELETE FROM AuditTrail a WHERE a.rid = Cur_DelAudit.RID;
     counter:=counter+1;
   end loop;
   dbms_output.put_line('counter='||counter);
end;
/

counter=12154

PL/SQL procedure successfully completed.

Elapsed: 00:00:07.09
SQL> rollback;

Rollback complete.


-- new method 1:

declare
   counter             number;
begin
   counter := 0;
   loop
     delete from AuditTrail  
     where RID in (SELECT AuditTrail.RID
                   FROM    AuditTrail, Customers, Banks, auditedUsers
                   WHERE AuditTrail.UserRID = AuditedUsers.userRID
               AND      auditedUsers.Customerrid = Customers.RID
               AND      Customers.Bank = Banks.RID
               AND      TRUNC(AuditTrail.DateTime) < (TRUNC(SYSDATE)
- NVL(Customers.AUDITRETENTIONPERIOD, Banks.AUDITRETENTIONPERIOD)))
     and   rownum <= 1000;
     counter := counter + sql%rowcount;
     exit when sql%rowcount = 0;    
 end loop;
 dbms_output.put_line('counter='||counter);
end;
/


counter=12154

PL/SQL procedure successfully completed.

Elapsed: 00:00:16.01
SQL> rollback;

Rollback complete.



-- new method2:

declare
   counter             number;
begin
   counter := 0;
   loop
     delete from AuditTrail  A
     where UserRID in (SELECT AuditedUsers.userRID
                       FROM   Customers, Banks, auditedUsers
                       WHERE  auditedUsers.Customerrid = Customers.RID
                 AND    Customers.Bank = Banks.RID)
     AND  (TRUNC(SYSDATE) - TRUNC(A.DateTime)) > (select
NVL(Customers.AUDITRETENTIONPERIOD, Banks.AUDITRETENTIONPERIOD)
                                                  from   Customers, Banks,
auditedUsers
                                                  WHERE
auditedUsers.Customerrid = Customers.RID
                                            AND    Customers.Bank =
Banks.RID
                                                  AND
AuditedUsers.userRID = A.UserRID)
     and   rownum <= 1000;
     counter := counter + sql%rowcount;
     exit when sql%rowcount = 0;    
 end loop;
 dbms_output.put_line('counter='||counter);
end;
/

counter=12154

PL/SQL procedure successfully completed.

Elapsed: 00:00:22.03
SQL> rollback;

Rollback complete.

*************************************************************************
PRIVILEGED AND CONFIDENTIAL:
This communication, including attachments, is for the exclusive use of
addressee and may contain proprietary, confidential and/or privileged
information.  If you are not the intended recipient, any use, copying,
disclosure, dissemination or distribution is strictly prohibited.  If you
are not the intended recipient, please notify the sender immediately by
return e-mail, delete this communication and destroy all copies.  
*************************************************************************
--
http://www.freelists.org/webpage/oracle-l