cursor游标
定义游标:cursor 游标名 is select 语句:
打开游标:open 游标名
提取游标:fetch 游标名 into 变量名
关闭游标:close 游标名
declare
cursor cur_1 is
select tid,title from logtypes ; ---------游标的声明
v_tid logtypes.tid%type;
v_title logtypes.title%type; ---------定义接收游标中的数据变量
v_typercd cur_1%rowtype ; --------通过记录来接受数据
begin
open cur_1; -------打开游标
loop
fetch cur_1 into v_tid,v_title ; ------取游标中的数据,遍历游标中的下一行数据
exit when cur_1%notfound ; -------检测是否已经达到最后一行
dbms_output.put_line('读取tid='||v_tid||' title='||v_title); --------输出游标中的数据
end loop;
close cur_1; --------关闭游标
open cur_1; -------打开游标
loop
fetch cur_1 into v_typercd ;
exit when cur_1%notfound ;
dbms_output.put_line('--//读取tid='||v_typercd.tid||' title='||v_typercd.title);
end loop;
close cur_1; ------关闭游标
-----for循环游标
for tmp_record in cur_1 loop
dbms_output.put_line('++//读取tid='||tmp_record.tid||' title='||tmp_record.title);
end loop;
end;