Sequence Control Statements in PLSQL


--====================================================
Sequential Control Statements
GOTO Statement :- The GOTO statement, which goes to a specified statement
NULL Statement :- The NULL statement, which does nothing
--====================================================
Example :-  GOTO Statement
--====================================================

DECLARE
 
BEGIN

  FOR i in 1..10 LOOP   
    dbms_output.put_line ('loop run for :- '||i);
  
--    IF i = 7 THEN
--    GOTO JUMP ;
--    ELSIF i = 5 THEN
--    GOTO hello ;
--    END IF;
   
  END LOOP;
 
  <<JUMP>>
  DBMS_OUTPUT.PUT_LINE('Now i am 7 and i am out side the loop');
 
  <<hello>>
  DBMS_OUTPUT.PUT_LINE('Now i am 5 and i am out side the loop');
 
END;

-- OUTPUT
loop run for :- 1
loop run for :- 2
loop run for :- 3
loop run for :- 4
loop run for :- 5
loop run for :- 6
loop run for :- 7
loop run for :- 8
loop run for :- 9
loop run for :- 10
Now i am 7 and i am out side the loop
Now i am 5 and i am out side the loop

--====================================================
DECLARE
 
BEGIN

  FOR i in 1..10 LOOP   
    dbms_output.put_line ('loop run for :- '||i);
  
    IF i = 7 THEN
    GOTO JUMP ;
    ELSIF i = 5 THEN
    GOTO hello ;
    END IF;
   
  END LOOP;
 
  <<JUMP>>
  DBMS_OUTPUT.PUT_LINE('Now i am 7 and i am out side the loop');
 
  <<hello>>
  DBMS_OUTPUT.PUT_LINE('Now i am 5 and i am out side the loop');
 
END;

-- OUTPUT
loop run for :- 1
loop run for :- 2
loop run for :- 3
loop run for :- 4
loop run for :- 5
Now i am 5 and i am out side the loop

--====================================================
Example :-  NULL Statement Allows GOTO to Label
--====================================================


DECLARE
 
BEGIN

  FOR i in 1..10 LOOP   
    dbms_output.put_line ('loop run for :- '||i);
  
    IF i = 5 THEN
    GOTO JUMP_NOW ;
    END IF;
   
  END LOOP;
 
  <<JUMP_NOW>>
  NULL;
 
END;

-- OUTPUT
loop run for :- 1
loop run for :- 2
loop run for :- 3
loop run for :- 4
loop run for :- 5

--====================================================
Example :-  NULL Statement
--====================================================
DECLARE
 
BEGIN

  FOR i in 1..10 LOOP   
  
    IF i = 5 THEN
        dbms_output.put_line ('loop run for :- '||i);
    ELSE
    NULL;
    END IF;
   
  END LOOP;
 
END;

-- OUTPUT
loop run for :- 5


Comments

Popular posts from this blog

E-Text Report In Fusion | Types of E-Text reports

Supplier API's

How to pass default Parameter in cursor