Call function in PL/SQL : Nested Block « PL SQL Statements « Oracle PL/SQL Tutorial






SQL> set serveroutput on
SQL> set echo on
SQL>
SQL>    CREATE OR REPLACE function letterCounter(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         END LOOP;
 14         RETURN v_counter ;
 15    END letterCounter;
 16    /

Function created.

SQL>
SQL>   DECLARE
  2         v_MYTEXT VARCHAR2(20) := 'THIS IS A TEST';
  3    BEGIN
  4         DBMS_OUTPUT.PUT_LINE('Total count is ' || letterCounter(v_MYTEXT));
  5    END;
  6    /
Total count is 11

PL/SQL procedure successfully completed.

SQL>
SQL>








22.12.Nested Block
22.12.1.Nested Blocks
22.12.2.A nested block which declares and prints a variable of the same name
22.12.3.This is an example of nested anonymous blocks
22.12.4.Nesting Functions and Procedures
22.12.5.Call function in PL/SQL