首页 > 数据库 > Oracle > oracle游标简单使用小记
随手练习了下oracle游标,小记如下:
###################### 游标之loop #############################
declare
v_dpn scott.dept.deptno%type;
v_name scott.dept.dname%type;
v_loc scott.dept.loc%type;
cursor c_dept is select * from scott.dept;
begin
open c_dept;
loop
fetch c_dept into v_dpn,v_name,v_loc;
exit when c_dept%notfound;
dbms_output.put_line(v_dpn||'***'||v_name||'***'||v_loc);
end loop;
close c_dept;
end;
/
###################### 游标之for loop ###########################
declare
cursor c_dept is select * from scott.dept;
begin
for v_x in c_dept loop
dbms_output.put_line(v_x.deptno||'**'||v_x.dname||'**'||v_x.loc);
end loop;
end;
/
################## 游标之 open for ########################
declare
v_x scott.dept%rowtype;
type c_dept is ref cursor return scott.dept%rowtype;
vc_dept c_dept;
begin
open vc_dept for
select * from scott.dept;
loop
fetch vc_dept into v_x;
exit when vc_dept%notfound;
dbms_output.put_line(v_x.deptno||'**'||v_x.dname||'**'||v_x.loc);
end loop;
end;
/
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/28612416/viewspace-1083964/ ,如需转载,请注明出处,否则将追究法律责任。