1、游標的分類
隱式游標:所有的select語句和DML語句,內在都含有游標。
顯式游標:有開發人員聲明和控制。用于從結果集中取出多行數據,并將多行數據一行一行單獨進行處理。***
2、定義游標
declare
cursor 游標名稱
is
查詢語句;
begin
--其他語句
end;
列子:
declare
cursor cur_stu
is
select name from student where id=2;
sname student.name%type;
result varchar2(20);
begin
open cur_stu;
loop
fetch cur_stu into sname;
exit when cur_stu%notfound;
result:=result||sname||'';
end loop;
dbms_output.put_line('我的名字叫' || result);
close cur_stu;
end;
浙公網安備 33010602011771號