Oracle使用行类型变量获取游标信息
(1) 表数据
SQL> select * from scott.dept;
DEPTNO DNAME LOC
---------- ---------- ----------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
(2) 程序编写
set serverout on;
--声明游标变量
declare cursor cu_dept is select * from dept;
--声明行类型变量
dept_new dept%rowtype;
begin
open cu_dept;
fetch cu_dept into dept_new;
while cu_dept%found loop
dbms_output.put_line(dept_new.deptno || ':' || dept_new.dname || ':' || dept_new.loc);
fetch cu_dept into dept_new;
end loop;
close cu_dept;
end;
/
(3) 运行结果
10:ACCOUNTING:NEW YORK
20:RESEARCH:DALLAS
30:SALES:CHICAGO
40:OPERATIONS:BOSTON
PL/SQL procedure successfully completed.
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29485627/viewspace-1246737/
,如需转载,请注明出处,否则将追究法律责任。