Impact of EXIT in a function : EXIT « PL SQL « Oracle PL / SQL






Impact of EXIT in a function

 

SQL>
SQL> -- Impact of EXIT in a function.
SQL>
SQL> CREATE OR REPLACE FUNCTION exitfunc(p_pass_string VARCHAR2)
  2        RETURN NUMBER IS
  3             len Number := 1;
  4  BEGIN
  5        WHILE len <= LENGTH(p_PASS_STRING) LOOP
  6             len := len + 1;
  7             EXIT WHEN SUBSTR(p_PASS_STRING,len,1) = ' ';
  8        END LOOP;
  9        RETURN len ;
 10  END exitfunc;
 11  /

Function created.

SQL>
SQL>
SQL> --  Executing EXIT within a function.
SQL> DECLARE
  2       v_MYTEXT VARCHAR2(20) := 'THIS IS A TEST';
  3  BEGIN
  4       DBMS_OUTPUT.PUT_LINE('Total count is ' || exitfunc(v_MYTEXT));
  5  END;
  6  /
Total count is 5

PL/SQL procedure successfully completed.

SQL>
           
         
  








Related examples in the same category

1.Using EXIT with a simple LOOP
2.Using EXIT with a WHILE loop
3.Using EXIT with a FOR loop
4.Unconstrained loop: exit
5.Exit outer loop with 'EXIT LabelName When' statement
6.EXIT WHEN clause.
7.Exit to a label
8.Exit loop since last index value is read.