Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

pl/sql not working

Posted on 2014-03-27
3
Medium Priority
?
515 Views
Last Modified: 2014-03-27
Hi experts.
The execution of the following procedure is not working.
Any clues?

CREATE OR REPLACE procedure SYSTEM.del1_dw_service_orders is
   CURSOR del1 is
   select * from dw.dw_service_orders where to_char(transaction_date,'RR')='14' for update;
   del1_rec dw.dw_service_orders%ROWTYPE;
BEGIN
    execute immediate 'alter session enable parallel DML';
   OPEN del1;
   LOOP
    fetch del1 into del1_rec;
    exit when del1%NOTFOUND;
      delete from dw.dw_service_orders where current of del1;
       if del1%ROWCOUNT > 100
       then
       commit;
       END IF;
     END LOOP;
   CLOSE del1;
   commit;
END;
/




SQL> SQL> SQL> mapdbprd-oracle:/home/oracle/dba/scripts/Mapdb> cat del_dw_serv_orders.log
SQL> execute system.del1_dw_service_orders;
BEGIN system.del1_dw_service_orders; END;

*
ERROR at line 1:
ORA-01002: fetch out of sequence
ORA-06512: at "SYSTEM.DEL1_DW_SERVICE_ORDERS", line 9
ORA-06512: at line 1


Elapsed: 00:43:21.01
SQL> spool off;
0
Comment
Question by:LindaC
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
johnsone earned 2000 total points
ID: 39959291
First off, this procedure should not be created in the SYSTEM schema.  That is reserved for Oracle objects and you could run into issues at a later date.

The RR date format isn't doing anything for you that YY doesn't do because you are converting to character.

You don't have to do all the cursor manipulation yourself.  The looping structure in Oracle will do it for you.

You shouldn't be selecting the entire record.  There is no need to be passing all that data through memory when you aren't using it.

This is a simplified version of what you had originally.

CREATE OR replace PROCEDURE SYSTEM.Del1_dw_service_orders 
IS 
  commit_ctr PLS_INTEGER := 0; 
BEGIN 
    FOR del1_rec IN (SELECT ROWID 
                     FROM   dw.dw_service_orders 
                     WHERE  To_char(transaction_date, 'YY') = '14') LOOP 
        DELETE FROM dw.dw_service_orders 
        WHERE  ROWID = del1_rec.ROWID; 

        commit_ctr := commit_ctr + 1; 

        IF commit_ctr > 100 THEN 
          COMMIT; 

          commit_ctr := 1; 
        END IF; 
    END LOOP; 

    COMMIT; 
END; 

/ 

Open in new window


Be aware that this could result in a ORA-01555.  This is a classic case of fetch across commit.  If you aren't deleting that many records and the table is small enough that you can scan it and delete all the records before redo get used again, you may avoid it.  But, you some day in the future you could hit it.  Re-running could complete.  Just want you to be aware that it could happen.
0
 
LVL 8

Author Comment

by:LindaC
ID: 39959435
Oh wow!
I will be executing this.
0
 
LVL 8

Author Closing Comment

by:LindaC
ID: 39959504
Done.

Thank you!


rw-r--r--    1 oracle   dba             124 Mar 27 12:47 del_dw_serv_orders.log
-rw-r--r--    1 oracle   dba             496 Mar 27 12:47 del.log
mapdbprd-oracle:/home/oracle/dba/scripts/Mapdb> cat del.log

SQL*Plus: Release 11.2.0.3.0 Production on Thu Mar 27 12:34:41 2014

Copyright (c) 1982, 2011, Oracle.  All rights reserved.

SQL> Connected.
SQL> SQL>
Session altered.

Elapsed: 00:00:00.04
SQL>
Session altered.

Elapsed: 00:00:00.00
SQL>
Session altered.

Elapsed: 00:00:00.00
SQL> SQL> SQL>
PL/SQL procedure successfully completed.

Elapsed: 00:12:33.23
SQL> SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning option
mapdbprd-oracle:/home/oracle/dba/scripts/Mapdb>
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to recover a database from a user managed backup
Suggested Courses

879 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question