Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2016-10-28
7
Medium Priority
?
120 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 30

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
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.

 
LVL 14

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 14

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 2000 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

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.
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

715 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