I'm fairly new to Oracle, but have had a good search. Can someone explain the scoping rules in relation to this:
BEGIN
DECLARE
Variable1 number := 1;
BEGIN
DECLARE
Variable2 number := 2;
BEGIN
dbms_output.put_line('Variable1: ' || Variable1);
dbms_output.put_line('Variable2: ' || Variable2);
END;
BEGIN
dbms_output.put_line('Variable1: ' || Variable1);
dbms_output.put_line('Variable2: ' || Variable2);
END;
END;
END;
errors with:
Error report - ORA-06550: line 17, column 55: PLS-00201: identifier 'VARIABLE2' must be declared ORA-06550: line 17, column 17: PL/SQL: Statement ignored 06550. 00000 - "line %s, column %s:\n%s" *Cause: Usually a PL/SQL compilation error. *Action:
Why is Variable2 unavailable in my second attempt to output it? Is there a way to achieve access to Variable2 within the second BEGIN...END block, or is this just the way Oracle works?
I'm using Oracle 12c. Thanks!