复合变量composite,用于存放多个值的变量主要有:
- pl/sql记录
- pl/sql表
- 嵌套表
- varray
1.pl/sql记录
declare
--定义一个pl/sql记录类型emp_record_type 包含两个数据类型 spName,salary
type emp_record_type is record(spName emp.name%type,salary emp.sal%type);
--定义一个sp_record变量,这个变量的类型是emp_record_type
sp_record emp_record_type;
begin
select name,sal into sp_record from emp where id=&no;
dbms_output.put_line('姓名是:'||sp_record.spName||'工资是:'||sp_record.salary);
end;
/
pl/sql表实例
相当于高级语言中的数组
但高级语言数组下标不能为负数,而pl/sql下标可以为负数
declare
index by binary_integer 下标是整数
--定义一个pl/sql表实例emp_table_type
type emp_table_type is table of emp.name%type index by binary_integer;
--定义了sp_table 类型是emp_table_type
sp_table emp_table_type;
begin
select name into sp_table(0) from emp where id=&no; &no定义的变量
dbms_output.put_line('姓名是:'||sp_table(0));
end;
/