跟我学plsql - 写可执行的语句 (二)

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

shenghuiping2001

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值