-- 利用fetch...into 抓取游标数据 此种方式适用于数据量比较小的情况
declare
v_id t_user.user_id%type;
v_no t_user.user_no%type;
cursor cur is select user_id,user_no from t_user;
begin
open cur;
loop
fetch cur into v_id,v_no;
exit when cur%notfound;
if v_id = '1004' then
continue;
else
dbms_output.put_line(v_id || ' ' || v_no);
end if;
end loop;
close cur;-- 关闭游标
end;
-- 利用fetch... bulk collect into
--抓取游标数据 此种方式在数据量大的情况下效率高于fetch...into
declare
type user_type is table of t_user%rowtype;
v_user user_type;
cursor cur is
select * from t_user t;
v_count number := 0;
begin
open cur;
-- loop --这块也加了个循环,有点不太明白,目测是防止抓取数时候出现异常
fetch cur bulk collect
into v_user;
-- exit when cur%notfound;--退出在此处无结果输出
for i in 1 .. v_user.count loop
dbms_output.put_line('id=' || v_user(i).user_id || ' name==' || v_user(i)
.user_name);
end loop;
v_count := v_count + 1;
--exit when cur%notfound;--退出在此处正确输出结果
-- end loop;
dbms_output.put_line('count==' || v_count);
close cur;
end;
--
declare
cursor cur is
select * from t_user;
begin
for v_user in cur loop
dbms_output.put_line('id is ' || v_user.user_id || ' name is ' ||
v_user.user_name);
end loop;
end;
declare
v_id t_user.user_id%type;
v_no t_user.user_no%type;
cursor cur is select user_id,user_no from t_user;
begin
open cur;
loop
fetch cur into v_id,v_no;
exit when cur%notfound;
if v_id = '1004' then
continue;
else
dbms_output.put_line(v_id || ' ' || v_no);
end if;
end loop;
close cur;-- 关闭游标
end;
-- 利用fetch... bulk collect into
--抓取游标数据 此种方式在数据量大的情况下效率高于fetch...into
declare
type user_type is table of t_user%rowtype;
v_user user_type;
cursor cur is
select * from t_user t;
v_count number := 0;
begin
open cur;
-- loop --这块也加了个循环,有点不太明白,目测是防止抓取数时候出现异常
fetch cur bulk collect
into v_user;
-- exit when cur%notfound;--退出在此处无结果输出
for i in 1 .. v_user.count loop
dbms_output.put_line('id=' || v_user(i).user_id || ' name==' || v_user(i)
.user_name);
end loop;
v_count := v_count + 1;
--exit when cur%notfound;--退出在此处正确输出结果
-- end loop;
dbms_output.put_line('count==' || v_count);
close cur;
end;
--
declare
cursor cur is
select * from t_user;
begin
for v_user in cur loop
dbms_output.put_line('id is ' || v_user.user_id || ' name is ' ||
v_user.user_name);
end loop;
end;