Exit a function : Function « Function Procedure Packages « Oracle PL/SQL Tutorial






SQL> set serveroutput on
SQL> set echo on
SQL>
SQL>    CREATE OR REPLACE function exitfunc(myString VARCHAR2)
  2          RETURN NUMBER IS
  3               v_current_position INTEGER := 1;
  4               v_counter NUMBER := 0;
  5     BEGIN
  6          WHILE v_current_position <= LENGTH(myString) LOOP
  7               IF SUBSTR(myString,v_current_position,1) != ' ' THEN
  8                    v_counter := v_counter + 1;
  9               ELSE
 10                   NULL;
 11              END IF;
 12              v_current_position := v_current_position + 1;
 13              EXIT WHEN SUBSTR(myString,v_current_position,1) = ' ';
 14         END LOOP;
 15         RETURN v_counter ;
 16    END exitfunc;
 17    /

Function created.

SQL>
SQL>
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 4

PL/SQL procedure successfully completed.

SQL>








27.1.Function
27.1.1.Functions
27.1.2.Describe a user-defined function
27.1.3.create or replace FUNCTION iifn(boolean_expression in BOOLEAN,true_number IN NUMBER,false_number IN NUMBER)
27.1.4.Storing PL/SQL function in the Database
27.1.5.Create a simple function
27.1.6.Creating a Function to deal with business rules
27.1.7.CREATE OR REPLACE a function
27.1.8.Calling a Function
27.1.9.Calling a Function for a table
27.1.10.Function without parameters
27.1.11.Exit a function
27.1.12.How to Call a Function from PL/SQL With or Without Parameters
27.1.13.Local Subprograms
27.1.14.Dependency Example
27.1.15.The FullName Function
27.1.16.PLW-05005: function NO_RETURN returns without value at line 21
27.1.17.Use function to check passwords