作用域:
declare
l_parent_number number;
begin
l_parent_number :=1;
declare
l_child_number number :=2;
begin
dbms_output.put_line(l_parent_number);
end;
l_child_number :=3;
end;
/
l_parent_number 整个块内都可见,l_child_number只在黑体部分可见。
可视性:
Declare
L_number1 number := l_number2;
L_number2 number :=10;
Begin
Null;
End;
/
只有声明之后,pl/sql才知道变量/常量的存在。
数据类型:
PL/SQL与SQL使用相同的数据类型,只是界限上有些不同。罗列一些不同。
记录:
TYPE
字段 类型。。。
);
declare
type location_record is record(
city varchar2(30),
state varchar2(30)
);
l_my_loc location_record;
begin
l_my_loc.city :=’Reston’;
l_my_loc.state :=’CA’;
dbms_output.put_line(l_my_loc.city);
dbms_output.put_line(l_my_loc.state);
end;
/
使用%TYPE和%ROWTYPE
%ROWTYPE: 当用户声明表示表,视图或者游标的某个行的记录变量时,使用
如果,不是声明整个行的变量,而是某个列的时候,使用%TYPE
connect hr/hr
desc departments
declare
l_dept departments%rowtype;
l_dept_name departments.department_name%type;
begin
l_dept.department_id:=1000;
l_dept.department_name:=’AA’;
insert into departments(department_id, department_name)
values(l_dept.department_id, l_dept.department_name);
l_dept.department_id:=1001;
l_dept_name:=’BB’;
insert into departments(department_id, department_name)
values(l_dept.department_id, l_dept_name);
end;
/