Saturday, June 15, 2019

Scope of Variable in PL/SQL

SQL> SET SERVEROUTPUT ON;
SQL>
SQL> DECLARE
  2     k   NUMBER := 10;
  3     v   NUMBER := 1;
  4  BEGIN
  5     v := v + 21;
  6  /* Inner block */
  7     DECLARE
  8        s   NUMBER := 0;
  9     BEGIN
 10        s := v;
 11        DBMS_OUTPUT.put_line ('s=' || s); -- can't use outside of this Inner block
 12     END;
 13  /* End Inner block */
 14     DBMS_OUTPUT.put_line ('s=' || s);
 15  END;
 16  /
   DBMS_OUTPUT.put_line ('s=' || s);
                                 *
ERROR at line 14:
ORA-06550: line 14, column 34:
PLS-00201: identifier 'S' must be declared
ORA-06550: line 14, column 4:
PL/SQL: Statement ignored

SQL> SET SERVEROUTPUT ON;
SQL>
SQL> DECLARE
  2     k   NUMBER := 10;
  3     v   NUMBER := 1;
  4  BEGIN
  5     v := v + 21;
  6  /* Inner block */
  7     DECLARE
  8        s   NUMBER := 0;
  9     BEGIN
 10        s := v;
 11        DBMS_OUTPUT.put_line ('s=' || s); -- can't use outside of this Inner block
 12     END;
 13  /* End Inner block */
 14     DBMS_OUTPUT.put_line ('v=' || v);
 15  END;
 16  /
s=22
v=22

PL/SQL procedure successfully completed.

No comments:

Post a Comment

Delete Row Button to all records of Interactive Report in Oracle Apex

 1. add 'Delete' Del column to Report Query 2. Set the Following Properties for the DEL Column Type: Link Heading: Delete Targ...