declare
-- Local variables here
CURSOR C_EVENT(ROW_NUM NUMBER DEFAULT 3) is
(select t.name from users t where rownum <ROW_NUM);
temp users.name%TYPE;
begin
-- for 遍历游标
for temp in C_EVENT(ROW_NUM=>2)
Loop
dbms_output.put_line('名称:'|| temp.name);
dbms_output.put_line('index: '||C_EVENT%ROWCOUNT);
End Loop;
dbms_output.put_line('------分割线------');
--while 遍历游标
OPEN C_EVENT(ROW_NUM=>3);--打开游标
FETCH C_EVENT into temp; --取值
while C_EVENT%found
Loop
dbms_output.put_line('名称:'||temp); --打印
dbms_output.put_line('index: '||C_EVENT%ROWCOUNT);
FETCH C_EVENT into temp; --取值
End Loop;
CLOSE C_EVENT;
dbms_output.put_line('------分割线------');
--loog 遍历游标
OPEN C_EVENT(ROW_NUM=>4);--打开游标
Loop
FETCH C_EVENT into temp; --取值
Exit when C_EVENT%NOTFOUND;
dbms_output.put_line('名称:'||temp); --打印
dbms_output.put_line('index: '||C_EVENT%ROWCOUNT);
End Loop;
CLOSE C_EVENT;
end;
-------while..and...
declare
-- Local variables here
CURSOR C_EVENT(ROW_NUM NUMBER DEFAULT 3) is
(select t.name,t.status from users t where rownum <ROW_NUM);
temp users.name%TYPE;pp users.status%type; v_num int;
begin
--while 遍历游标
OPEN C_EVENT(ROW_NUM=>10);--打开游标
FETCH C_EVENT into temp,pp; --取值
v_num:=1;
while C_EVENT%found and v_num<=9
Loop
dbms_output.put_line('名称'||temp||'状态'||pp||'v_num'||v_num); --打印
dbms_output.put_line('index: '||C_EVENT%ROWCOUNT);
FETCH C_EVENT into temp,pp; --取值
v_num:=v_num+1;
End Loop;
CLOSE C_EVENT;
end;