oracle遊標簡單使用小記

流浪的野狼發表於2014-02-19

隨手練習了下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部落格 ” ,連結:http://blog.itpub.net/28612416/viewspace-1083964/,如需轉載,請註明出處,否則將追究法律責任。

相關文章