游标的三种处理方式
1.单条处理
open 游标;
LOOP
FETCH 游标 INTO 变量;
EXIT WHEN 条件;
END LOOP;
CLOSE 游标;
2.批量处理
open 游标;
FETCH 游标 BULK COLLECT INTO 集合变量;
CLOSE 游标;
3.隐式游标
for x in (sql语句) loop
...--逻辑处理
end loop;
1. FETCH游标loop的方式,--4.453
a.
DECLARE
CURSOR C_CUR IS
SELECT * FROM C_RESIDENTCUSTOMER;
C_CUR_ROW C_CUR%ROWTYPE;
BEGIN
OPEN C_CUR;
LOOP
FETCH C_CUR
INTO C_CUR_ROW;
EXIT WHEN C_CUR%NOTFOUND;
END LOOP;
CLOSE C_CUR;
END;
b.另一种写法
DECLARE
CURSOR C_CUR IS
SELECT * FROM C_RESIDENTCUSTOMER;
C_CUR_ROW C_CUR%ROWTYPE;
BEGIN
OPEN C_CUR;
FETCH C_CUR
INTO C_CUR_ROW;
WHILE C_CUR%FOUND LOOP
NULL;
FETCH C_CUR
INTO C_CUR_ROW;
END LOOP;
END;
2.fetch游标,一次取到游标变量中
--0.015
DECLARE
CURSOR C_CUR IS
SELECT * FROM C_RESIDENTCUSTOMER;
C_CUR_ROW C_CUR%ROWTYPE;
BEGIN
OPEN C_CUR;
FETCH C_CUR
INTO C_CUR_ROW;
CLOSE C_CUR;
END;
3.for LOOP循环的两种写法
--a.1.671
DECLARE
CURSOR C_CUR IS
SELECT * FROM C_RESIDENTCUSTOMER;
C_CUR_ROW C_CUR%ROWTYPE;
BEGIN
FOR C_CUR_ROW IN C_CUR LOOP
NULL;
END LOOP;
END;
--b.1.656
DECLARE
BEGIN
FOR I IN (SELECT * FROM C_RESIDENTCUSTOMER) LOOP
NULL;
END LOOP;
END;