PL/SQL & SQL CODING GUIDELINE 41 - Always use a CURSOR FOR loop to process the complete cursor results unless you are using bulk operations

條款四十一,總是使用 CURSOR for loop,除非使用 Bulk operations。


像是下面這樣的程式:

1
2
3
4
5
6
7
8
9
10
...
BEGIN
<<read_employees>>
LOOP
FETCH c_employees INTO r_employee;
EXIT read_employees WHEN c_employees%NOTFOUND;

END LOOP read_employees;
CLOSE c_employees;
END;


可以像下面這樣改寫,程式碼的維護性會比較好。

1
2
3
4
5
6
7
8
...
BEGIN
<<read_employees>>
FOR r_employee IN c_employee
LOOP

END LOOP read_employees;
END;