Solved

Is it possible to CONTINUE a loop from an exception in oracle pl/sql?

Posted on 2016-10-28
7
102 Views
Last Modified: 2016-11-01
Is it possible to CONTINUE a loop from an exception in oracle pl/sql?
 
Here is part of the code, When I run the program it's not recognizing the CONTINUE statement at the exception.  I want the program to continue after the insert statement at the exception.

      Begin
       
          dbms_output.put_line('inside_pprec');
 
           SELECT 'Z'
           INTO p_id
           FROM LEVY
           WHERE parid = dq_rec.parid
           AND taxyr = dq_rec.taxyr
           AND (dq_rec.user9 is null or dq_rec.user10 is null)
           AND (CASESTAT <> 'A' or cur = 'D');
           dbms_output.put_line (''||P_id );
           
        IF P_id = 'Z'
          THEN
               UPDATE LEVY
                SET DEACTIVAT = null,
                STATUS            = '3',
                LEVYTYPE         = 'SC',
                CASESTAT       = 'A',
                SALEDATE       = '&&p_Saledt',
                LEVY1         = '1',
                LEVYDATE1         = SYSDATE,
                USER1          = (select nvl(decode(dq_rec.prop_type,'H',r_ppadmn.user30,r_ppadmn.user5),user11) from PARDAT where parid = dq_rec.parid  AND taxyr = dq_rec.taxyr and cur = 'Y'),
                USER2          = decode(dq_rec.prop_type,'MH',r_ppadmn.user2),
                USER3          = decode(dq_rec.rolltype,'RE',null,r_ppadmn.user3),
                USER4         = (select nvl(flag1,'N') from ASMT where parid = dq_rec.parid  AND taxyr = dq_rec.taxyr and cur = 'Y'),
                USER20         = decode(dq_rec.rolltype,'RE',null,r_ppadmn.user19),
                USER21         = decode(dq_rec.rolltype,'RE',null,r_ppadmn.user17),    
                USER23         = decode(dq_rec.rolltype,'RE',null,r_ppadmn.user18),  
                USER24         = decode(dq_rec.rolltype,'RE',null,r_ppadmn.user51)    
                WHERE parid = dq_rec.parid
                AND taxyr = dq_rec.taxyr;
         END IF;
           
       Exception
        When no_data_found
        THEN
                   dbms_output.put_line ('Exception'||p_caseno|| '  '||dq_rec.PARID);
            INSERT INTO LEVY (JUR,PARID,TAXYR,ROLLTYPE,CASENO,STATUS,LEVYTYPE,CASESTAT,LEVY1,LEVYDATE1,USER1,USER2,USER3,USER20,USER21,USER23,USER24,user4)
            VALUES(dq_rec.JUR,dq_rec.PARID,dq_rec.TAXYR,dq_rec.ROLLTYPE,p_caseno,'3','SC','A','1',SYSDATE,decode(dq_rec.prop_type,'H',r_ppadmn.user30,r_ppadmn.user5),
                    decode(dq_rec.prop_type,'MH',r_ppadmn.user2),decode(dq_rec.rolltype,'RE',null,r_ppadmn.user3),decode(dq_rec.rolltype,'RE',null,r_ppadmn.user19),decode(dq_rec.rolltype,'RE',null,r_ppadmn.user17),decode(dq_rec.rolltype,'RE',null,r_ppadmn.user18),decode(dq_rec.rolltype,'RE',null,r_ppadmn.user51),(select nvl(flag1,'N') from ASMT where parid = dq_rec.parid  AND taxyr = dq_rec.taxyr and cur = 'Y') );
             CONTINUE;      
 --      commit;
       End;
0
Comment
Question by:Tanuja Kadam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 74

Expert Comment

by:sdstuber
ID: 41864643
there are no loops in your code.  What are you expecting to "continue"  ?
0
 
LVL 28

Expert Comment

by:Pawan Kumar
ID: 41864723
Can you try the code after removing the Continue keyword.  Continue statement is for loops. Sample code..

DECLARE
   Counter number(2) := 1;
BEGIN
    
   WHILE Counter < 5 LOOP
      dbms_output.put_line (Counter);
      Counter := Counter + 1;
      IF Counter = 3 THEN         
         Counter := Counter + 1;
         CONTINUE;
      END IF;
   END LOOP;
END;
/

Open in new window


O/p
1
2
4

So effectively continue statement will move the execution to the next iteration.
Hope it helps !!
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 41864734
A pretty big guess here is that is the nested PL/SQL block of a larger stored procedure.

If so, I don't think the continue is where it should be.  The nested block is sort of it's own island and controls itself.

If it gets a no_data_found exception then it does the insert.

HOWEVER, if the insert causes an exception, there is no handler for that so it isn't trapped.

You might need to put another nested pl/sql block in the insert and trap errors inside there.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Expert Comment

by:Alexander Eßer [Alex140181]
ID: 41866539
The exact answer to the titled question
Is it possible to CONTINUE a loop from an exception in oracle pl/sql?
is quite as simple as short: NO
0
 
LVL 13

Expert Comment

by:Alexander Eßer [Alex140181]
ID: 41866541
If a loop breaks due to an exception where do you want to continue?! The whole context is lost. If you handle that very exception within the loop's boundaries then the answer would be sort of yes (but not in the context of the main question).
0
 

Author Comment

by:Tanuja Kadam
ID: 41866745
Yes...I wouls like the code to continue after the execution of exception(insert). There is more code after this block.
0
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 41866772
Then create the nested PL/SQL block with its own exception handler as I suggested.

This is untested but something like this:
...
Exception
         When no_data_found
         THEN
                    dbms_output.put_line ('Exception'||p_caseno|| '  '||dq_rec.PARID);
            BEGIN
                 INSERT INTO LEVY      (JUR,PARID,TAXYR,ROLLTYPE,CASENO,STATUS,LEVYTYPE,CASESTAT,LEVY1,LEVYDATE1,USER1,USER2,USER3,USER20,USER21,USER23,USER24,user4)
                 VALUES(dq_rec.JUR,dq_rec.PARID,dq_rec.TAXYR,dq_rec.ROLLTYPE,p_caseno,'3','SC','A','1',SYSDATE,decode(dq_rec.prop_type,'H',r_ppadmn.user30,r_ppadmn.user5),
                        decode(dq_rec.prop_type,'MH',r_ppadmn.user2),decode(dq_rec.rolltype,'RE',null,r_ppadmn.user3),decode(dq_rec.rolltype,'RE',null,r_ppadmn.user19),decode(dq_rec.rolltype,'RE',null,r_ppadmn.user17),decode(dq_rec.rolltype,'RE',null,r_ppadmn.user18),decode(dq_rec.rolltype,'RE',null,r_ppadmn.user51),(select nvl(flag1,'N') from ASMT where parid = dq_rec.parid  AND taxyr = dq_rec.taxyr and cur = 'Y') );
              
             EXCEPTION WHEN OTHERS THEN NULL;
            END;
        End; 
...

Open in new window


If you want to take some other action or only continue on specific errors, adjust the WHEN OTHERS as necessary.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
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
Via a live example, show how to take different types of Oracle backups using RMAN.

739 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