oracle 显式游标,oracle的显式游标

5268f80b9b1e01f982625ef6fac83ca1.png

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行对象一致的集合类型cur_row_user,

用于存放批量得到的数据

*/

cur_row_user my_user_tab;

begin

open row_user;

loop

/*从结果集中提取数据,每次提取两行*/

fetch row_user bulk collect into cur_row_user limit 2;

/*遍历集合cur_row_user中的数据*/

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行对象一致的集合类型cur_user_cur,

用于存放批量得到的数据

*/

cur_user_cur my_user_tab;

begin

open user_cur;

loop

/*从结果集中提取数据,每次提取两行*/

fetch user_cur bulk collect into cur_user_cur limit 2;

/*遍历集合cur_user_cur中的数据*/

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 不需要特别的申明变量,它可以提取出行对象类型数据*/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('游标没有打开');

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('游标没有打开');

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('游标没有打开');

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('游标没有打开');

exit;

end if;

end loop;

end;

oracle的显式游标

标签:oracle的显式游标

1428d0e076c3959ab11d28a39bc84fab.png

5268f80b9b1e01f982625ef6fac83ca1.png

本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉

本文系统来源:http://blog.51cto.com/matengbing/2044941

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值