declare cursor user_cur is select * from my_user; user_row my_user%rowtype; begin open user_cur; loop fetch user_cur into user_row; exit when user_cur%notfound; dbms_output.put_line(user_row.user_id||'----'||user_row.name); end loop; close user_cur; end;
declare cursor user_cur is select * from my_user; row_user my_user%rowtype; begin open user_cur; loop fetch user_cur into row_user; exit when user_cur%notfound; dbms_output.put_line(row_user.user_id||'----'||row_user.name||'----'||row_user.age); end loop; close user_cur; end;
declare cursor row_user is select * from my_user; type my_user_tab is table of my_user%rowtype; /* 定義和表my_user行對(duì)象一致的集合類型cur_row_user, 用于存放批量得到的數(shù)據(jù) */ cur_row_user my_user_tab; begin open row_user; loop /*從結(jié)果集中提取數(shù)據(jù),每次提取兩行*/ fetch row_user bulk collect into cur_row_user limit 2; /*遍歷集合cur_row_user中的數(shù)據(jù)*/ for i in 1..cur_row_user.count loop dbms_output.put_line(cur_row_user(i).user_id||'----'||cur_row_user(i).name||'----'||cur_row_user(i).age); end loop; exit when row_user%notfound; end loop; close row_user; end;
declare cursor user_cur is select * from my_user; type my_user_tab is table of my_user%rowtype; /* 定義和表my_user行對(duì)象一致的集合類型cur_user_cur, 用于存放批量得到的數(shù)據(jù) */ cur_user_cur my_user_tab; begin open user_cur; loop /*從結(jié)果集中提取數(shù)據(jù),每次提取兩行*/ fetch user_cur bulk collect into cur_user_cur limit 2; /*遍歷集合cur_user_cur中的數(shù)據(jù)*/ for i in 1..cur_user_cur.count loop dbms_output.put_line(cur_user_cur(i).user_id||'----'||cur_user_cur(i).name||'----'||cur_user_cur(i).age); end loop; exit when user_cur%notfound; end loop; close user_cur; end;
declare cursor user_cur is select * from my_user; begin for cdr in user_cur loop dbms_output.put_line(cdr.user_id||'----'||cdr.name||'----'||cdr.age); end loop; end; /*cursor for loop 不需要特別的申明變量,它可以提取出行對(duì)象類型數(shù)據(jù)*/
declare
cursor user_cur
is select *
from my_user;
cdr my_user%rowtype;
begin
if user_cur%isopen then
fetch user_cur into cdr;
dbms_output.put_line(cdr.user_id||'----'||cdr.name||'----'||cdr.age);
else dbms_output.put_line('游標(biāo)沒有打開');
end if;
end;declare
cursor user_cur
is select *
from my_user;
cdr my_user%rowtype;
begin
open user_cur;
if user_cur%isopen then
loop
fetch user_cur into cdr;
exit when user_cur%notfound;
dbms_output.put_line(cdr.user_id||'----'||cdr.name||'----'||cdr.age);
end loop;
else dbms_output.put_line('游標(biāo)沒有打開');
end if;
end;declare
cursor user_cur
is select *
from my_user;
cdr my_user%rowtype;
begin
open user_cur;
loop
fetch user_cur into cdr;
if user_cur%found then
dbms_output.put_line(cdr.user_id||'----'||cdr.name||'----'||cdr.age);
else
dbms_output.put_line('游標(biāo)沒有打開');
exit;
end if;
end loop;
end;declare
/*這里的取值寫在declare和begin中都可以*/
v_user_id my_user.user_id%type:='&v_user_id';
/*這里的v_user_id的類型寫number和my_user.user_id%type都可以*/
cursor c_my_user(v_user_id my_user.user_id%type)
is select *
from my_user
where user_id=v_user_id;
cdr my_user%rowtype;
begin
open c_my_user(v_user_id);
loop
fetch c_my_user into cdr;
if c_my_user%found then
dbms_output.put_line(cdr.user_id||'----'||cdr.name||'----'||cdr.age);
else
dbms_output.put_line('游標(biāo)沒有打開');
exit;
end if;
end loop;
end;
網(wǎng)頁題目:oracle的顯式游標(biāo)
瀏覽地址:http://chinadenli.net/article30/ipjcso.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作、面包屑導(dǎo)航、網(wǎng)站收錄、App開發(fā)、網(wǎng)站策劃、全網(wǎng)營銷推廣
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)