参照变量不属于复合变量:
参照变量是指用于存放数值指针的变量,通过使用参照变量,
可以使得应用程序共享相同的对象,从而降低占用的空间,在编写pl/sql的程序时,
可以使用游标变量(ref cursor)和对象类型变量(ref obj_type)两种参照变量类型。
参照变量-ref cursor
使用游标时,当定义游标时不需要指定相应的select语句,但是当使用
游标时(open时)需要指定select语句,这样一个游标就于一个select语句结合了。实例如下:
--编写一个pl/sql块,可是输入部门号,并显示该部门的所有员工姓名和他的工资。
declare
--定义游标类型
type sp_emp_cursor is ref cursor;
--定义游标变量
test_cursor sp_emp_cursor;
--定义变量
v_ename emp.ename%type;
v_sal emp.sal%type;
begin
--执行
--把test_cursor和一个select结合
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;
dbms_output.put_line('名字:'||v_ename||',工资:'||v_sal);
end loop;
end;
参照变量是指用于存放数值指针的变量,通过使用参照变量,
可以使得应用程序共享相同的对象,从而降低占用的空间,在编写pl/sql的程序时,
可以使用游标变量(ref cursor)和对象类型变量(ref obj_type)两种参照变量类型。
参照变量-ref cursor
使用游标时,当定义游标时不需要指定相应的select语句,但是当使用
游标时(open时)需要指定select语句,这样一个游标就于一个select语句结合了。实例如下:
--编写一个pl/sql块,可是输入部门号,并显示该部门的所有员工姓名和他的工资。
declare
--定义游标类型
type sp_emp_cursor is ref cursor;
--定义游标变量
test_cursor sp_emp_cursor;
--定义变量
v_ename emp.ename%type;
v_sal emp.sal%type;
begin
--执行
--把test_cursor和一个select结合
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;
dbms_output.put_line('名字:'||v_ename||',工资:'||v_sal);
end loop;
end;