This I will intruduce How to write excelent PLSQL:
Step1:
The scope of variables:
1: The internal variables can be only used in internal declaration.
2: The external variables can be used in whole declaration.
Step2:
Variable Visibility:
example:
SQL> declare
2 v_father_name varchar2(20) :='Patrick';
3 v_date_of_birth DATE :='20-Apr-1972';
4 begin
5 declare
6 v_child_name varchar2(20) := 'Mike';
7 v_date_of_birth DATE :='12-Dec-2008';
8 begin
9 DBMS_OUTPUT.put_line('Father''s Name: ' || v_father_name);
10 DBMS_OUTPUT.put_line('Date of Birth :' || v_date_of_birth);
11 DBMS_OUTPUT.put_line('Child''s Name: ' || v_child_name);
12 end;
13 DBMS_OUTPUT.put_line('Date of Birth: ' || v_date_of_birth);
14 end;
15 /
result:
Father'name : Patrick
Date of Birth : 12-DEC-02
Child's Name: Mike
Date of Birth: 20-APR-72
reason:
The internal variable named as the same as the external variable,
the internal code will understand the internal variables firstly.
Solution:
Code with flag:
example:
SQL> set serveroutput on
SQL> l
1 begin <<outer>>
2 declare
3 v_name varchar2(20) :='Sheng Huiping';
4 begin
5 declare
6 v_name varchar2(20) :='Sheng Xin';
7 begin
8 dbms_output.put_line('Father'' Name: ' || outer.v_name);
9 dbms_output.put_line('Child''s Name: ' || v_name);
10 end;
11 end;
12* end outer;
SQL> /
Father' Name: Sheng Huiping
Child's Name: Sheng Xin
PL/SQL 过程已成功完成。
Step3:
I will intreduce one little techonogy skill:
in vi environment:
using below command can set the change line automatic:
1: vi file_name
2: using ":",then "set autoident"
3: if you want to chane line with "caps" of 4 character space:
set autostop=4