Sponsored

An example is given below for PLSQL Goto Label command to instruct the control to go to specific line number on some condition.

Suppose you want to by pass the control to any particular line on exception when no_data_found occurs, to achieve this you have to give a label using <<anylabel>> to that particular line to point it at the time of requirement.

The following is an anonymous PL/SQL block demonstrating this scenario using <<Labels>> with GoTo Label statement:

SET SERVEROUTPUT ON;

DECLARE
   v   NUMBER;
BEGIN
   BEGIN
      SELECT 1
        INTO v
        FROM DUAL
       WHERE dummy = 'V';
   -- change dummy = 'X' to skip exception section
   EXCEPTION
      WHEN NO_DATA_FOUND
      THEN
         DBMS_OUTPUT.put_line ('NO_Data_Found occured.');
         GOTO mylabel;
   END;

   -- below code before <<mylabel>> would not be executed if an error occured above
   -- because in exception section above, it is sending control directly to label <<mylabel>>
   -- but if no error occurred above then the whole program would be executed

   v := v + 1;

   DBMS_OUTPUT.put_line ('The value of variable v is '||v);

  <<mylabel>>
   DBMS_OUTPUT.put_line ('After label processing starts.');
-- do some task here
END;
/
Labels PLSQL

Oracle Forms Recipes eBookDownload

PLSQL Goto label example. Jump the control to specific line in plsql procedure using labels.

Post a Comment

V. Kapoor

{picture#https://3.bp.blogspot.com/-q3wCssWUHo8/ViDFfCpPEuI/AAAAAAAAD0M/MHPvgnl3T3U/s1600/authpic.JPG} Vinish Kapoor is a Software Consultant, currently working in a reputed IT company in Noida, India and doing blogging on Oracle Forms, SQL and PLSQL topics. He is an author of an eBook Oracle Forms Recipes, which is available on Google play. {facebook#https://www.facebook.com/foxinfotech2014} {twitter#https://twitter.com/foxinfotech} {google#https://plus.google.com/u/0/+VKapoor/posts}
Fox Infotech. Powered by Blogger.