• Post author:
  • Post category:PLSQL
  • Reading time:3 mins read
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:
   v   NUMBER;
      SELECT 1
        INTO v
        FROM DUAL
       WHERE dummy = 'V';
   -- change dummy = 'X' to skip exception section
         DBMS_OUTPUT.put_line ('NO_Data_Found occured.');
         GOTO mylabel;
   -- 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);
   DBMS_OUTPUT.put_line ('After label processing starts.');
-- do some task here
Labels PLSQL

Vinish Kapoor

An Oracle Apex Consultant, Oracle ACE, and founder of foxinfotech.in and orclqa.com a question and answer forum for developers.