How to convert the anonymous block to label block.
0
How to convert the anonymous block to label block:
m NUMBER:=100;
BEGIN
m:=200;
DBMS_OUTPUT.PUT_LINE(‘The value of Outer m:’||m);
<<Block2>> DECLARE
m NUMBER:=300;
v_tol NUMBER;
m number:=400;
BEGIN
Block1.m:=500;
n:=600;
v_tol:=block1.m+n;
DBMS_OUTPUT.PUT_LINE(‘The sum of block1 m,n is:’||v_tol);
DBMS_OUTPUT.PUT_LINE(‘The value of Inner block is:’||m);
END
block2; DBMS_OUTPUT.PUT_LINE(‘The value of Outer m:’||m);
END block1;
SQL>create table nlj_acc_tab(
accno varchar2(20) constraint pk_accno primary key,
name varchar2(20) constraint nn_name not null,
acctype char constraint chk_atype check(acctype in(‘C’,’S’,’R’)),
doo timestamp DEFAULT sysdate,
bal number(7,2) constraint nn_bal not null);
- We need to place a label before the DECLARE keyword.
- The label can also can use appear after the END keyword and it is optional.
- The advantage of labelled block is that labelled blocks allow you to access those variables that would not be visible when using anonymous block.
m NUMBER:=100;
BEGIN
m:=200;
DBMS_OUTPUT.PUT_LINE(‘The value of Outer m:’||m);
<<Block2>> DECLARE
m NUMBER:=300;
v_tol NUMBER;
m number:=400;
BEGIN
Block1.m:=500;
n:=600;
v_tol:=block1.m+n;
DBMS_OUTPUT.PUT_LINE(‘The sum of block1 m,n is:’||v_tol);
DBMS_OUTPUT.PUT_LINE(‘The value of Inner block is:’||m);
END
block2; DBMS_OUTPUT.PUT_LINE(‘The value of Outer m:’||m);
END block1;
SQL>create table nlj_acc_tab(
accno varchar2(20) constraint pk_accno primary key,
name varchar2(20) constraint nn_name not null,
acctype char constraint chk_atype check(acctype in(‘C’,’S’,’R’)),
doo timestamp DEFAULT sysdate,
bal number(7,2) constraint nn_bal not null);
0 comments: