Oracle游標分為顯示游標和隱式游標
顯示游標(Explicit Cursor):在PL/SQL程序中定義的
隱式游標(Implicit Cursor):是指非PL/SQL程序中定義的
一
(
首先創建測試用表STUDENT
(
create or replace PROCEDURE PROC_STU
BEGIN
declare
cursor cur_stu is
select stuno
v_stuno varchar(
v_stuname varchar(
begin
open cur_stu;
fetch cur_stu into v_stuno
while cur_stu%found
loop
dbms_output
fetch cur_stu into v_stuno
end loop;
close cur_stu;
end;
END PROC_STU
(
create or replace PROCEDURE PROC_STU
BEGIN
declare
cursor cur_stu is
select stuno
v_stuno varchar(
v_stuname varchar(
begin
open cur_stu;
fetch cur_stu into v_stuno
loop
if cur_stu%found then
dbms_output
fetch cur_stu into v_stuno
else
exit;
end if;
end loop;
close cur_stu;
end;
END PROC_STU
(
create or replace PROCEDURE PROC_STU
BEGIN
declare
cursor cur_stu is
select stuno
begin
for stu in cur_stu
loop
dbms_output
end loop;
end;
END PROC_STU
(
create or replace
PROCEDURE PROC_STU
BEGIN
declare
cursor cur_stu is
select stuno
v_stuno varchar(
v_stuname varchar(
begin
open cur_stu;
loop
fetch cur_stu into v_stuno
exit when cur_stu%notfound;
dbms_output
end loop;
close cur_stu;
end;
END PROC_STU
二
create or replace PROCEDURE PROC_STU
BEGIN
update student set stuname=
if SQL%NOTFOUND then
insert into student(STUNO
values(
end if;
END PROC_STU
所有的SQL語句在上下文區內部都是可執行的
SQL游標
DELETE是自動打開和關閉
上面例子中就是通過SQL%NOTFOUND游標屬性判斷UPDATE語句的執行結果決定是否需要插入新記錄
)
From:http://tw.wingwit.com/Article/program/Oracle/201311/17531.html