复合类型-pl/sql记录
类似于高级语言中的结构体,引用记录成员时,必须要加记录变量作为前缀
declare
type emp_record_type is record(name emp.ename%type,salary emp.sal%type,title emp.job%type);
sp_record emp_record_type;
begin
select ename,sal,job into sp_record
from emp where empno=&no;
dbms_output.put_line('员工名:'||sp_record.name||' 工资:'||sp_record.salary||' 工作:'||sp_record.title);
end;
复合类型-pl/sql表
相当于高级语言中的数组。但是在高级语言中数组的下标不能为负数,而pl/sql是可以为负数的,并且表示元素的下标没有限制。实例如下:
pl/sql表实例
declare
--定义了一个表类型sp_table_type,该类型是用于存放emp.ename%type类型的数据
--index by binary_integer 表示下表是整数
type sp_table_type is table of emp.ename%type index by binary_integer;
--定义了一个sp_table变量,这个变量的类型是sp_table_type
sp_table sp_table_type;
begin
select ename into sp_table(0) from emp where empno=&no;
dbms_output.put_line('员工名:'||sp_table(0));
end;