Introduction

In the following code, the procedure my_function declares a variable, rating, and a function, value_check.

The function redeclares the variable.

Then the function references the global variable by qualifying it with the procedure name.

Demo

SQL>
SQL> CREATE OR REPLACE PROCEDURE my_function (my_val NUMBER) AS
  2    rating NUMBER := 3;
  3-- from   www.  j  a  v a2 s.  c  o m
  4    FUNCTION value_check RETURN BOOLEAN IS
  5      rating  NUMBER := 1;
  6      over_limit  BOOLEAN;
  7    BEGIN
  8      IF my_function.rating <= my_val THEN
  9        over_limit := FALSE;
 10      ELSE
 11        over_limit := TRUE;
 12        rating := my_val;
 13      END IF;
 14      RETURN over_limit;
 15    END value_check;
 16  BEGIN
 17    IF value_check THEN
 18      DBMS_OUTPUT.PUT_LINE('result (' || TO_CHAR(my_val) || ').  '
 19        || 'Rating: ' || TO_CHAR(rating));
 20    ELSE
 21      DBMS_OUTPUT.PUT_LINE
 22        ('Credit rating OK.  ' || 'Rating: ' || TO_CHAR(rating));
 23    END IF;
 24  END;
 25  /

Procedure created.

SQL>
SQL> BEGIN
  2    my_function(1);
  3  END;
  4  /
result (1).  Rating: 3

PL/SQL procedure successfully completed.

SQL>

Related Topic