How to convert the anonymous block to label block.

0
How to convert the anonymous block to label block:
  • 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.
SQL> <<Block1>> DECLARE
                  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);

 Click here to go to Back page

About the author

Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus. Aenean fermentum, eget tincidunt.

0 comments:

Recent Posts