1)复合类型
<1>记录
类似与高级语言中的结构体
declare type emp_record_type is record
(name emp.ename%type,
salary emp.ename%type,
title emp.job%type
);
sp_record emp_record_type;
begin
select ename,sal,job into sp_record from emp
where empno=7788;
end;
<2>pl/sql表
相当于高级语言中的数组
declare type sp_table_type is table of
--index by binary_integer表示下标是整数
name emp.ename%type index by binary_integer;
sp_table sp_table_type;
begin
select ename into sp_table(0) from emp
where empno=7788;
end;
2)参照变量
用于存放数组指针的变量。
分为游标变量和对象类型变量
declare
--定义游标
type sp_emp_cursor is ref cursor;
--定义一个游标变量
test_cursor sp_emp_cursor;
--定义变量
v_ename emp.ename%type;
v_sal emp.sal%type;
begin
open test_cursor for select ename,sal from emp where deptno=&no;
loop
fetch test_cursor into v_ename,v_sal;
--判定是否test_cursor为空
exit when test_cursor%notfound;
end loop;
end;
<1>记录
类似与高级语言中的结构体
declare type emp_record_type is record
(name emp.ename%type,
salary emp.ename%type,
title emp.job%type
);
sp_record emp_record_type;
begin
select ename,sal,job into sp_record from emp
where empno=7788;
end;
<2>pl/sql表
相当于高级语言中的数组
declare type sp_table_type is table of
--index by binary_integer表示下标是整数
name emp.ename%type index by binary_integer;
sp_table sp_table_type;
begin
select ename into sp_table(0) from emp
where empno=7788;
end;
2)参照变量
用于存放数组指针的变量。
分为游标变量和对象类型变量
declare
--定义游标
type sp_emp_cursor is ref cursor;
--定义一个游标变量
test_cursor sp_emp_cursor;
--定义变量
v_ename emp.ename%type;
v_sal emp.sal%type;
begin
open test_cursor for select ename,sal from emp where deptno=&no;
loop
fetch test_cursor into v_ename,v_sal;
--判定是否test_cursor为空
exit when test_cursor%notfound;
end loop;
end;