PL/SQL & SQL CODING GUIDELINE 42 - Always use a NUMERIC FOR loop to process a dense array

條款四十二,總是使用 NUMERIC FOR loop 去處理 dense array。


像是下面這樣的程式:

1
2
3
4
5
6
7
8
9
...
BEGIN
<<process_employees>>
LOOP
EXIT process_employees WHEN i > t_employees.COUNT();

i := i + 1;
END LOOP process_employees;
END;


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

1
2
3
4
5
6
7
8
...
BEGIN
<<process_employees>>
FOR i IN 1..t_employees.COUNT()
LOOP

END LOOP process_employees;
END;