DECLARE
TYPE salaryTab IS TABLE OF plch_employees.salary%TYPE;
s_tab salaryTab;
TYPE eTab IS RECORD (
last_name plch_employees.last_name%TYPE,
salary plch_employees.salary%TYPE
);
TYPE eTab1 IS TABLE OF eTab;
e_tab eTab1;
BEGIN
--fetch single col with bulk collect clause
SELECT salary BULK COLLECT INTO s_tab FROM plch_employees;
FOR i IN 1..s_tab.count
LOOP
dbms_output.put_line('fetch data by bulk: ' || s_tab(i));
END LOOP;--fetch single col with for clause
FOR eachrow IN (SELECT salary FROM plch_employees)
LOOP
dbms_output.put_line('fetch data by for: ' || eachrow.salary);END LOOP;--fetch multiple cols with bulk collect clauseSELECT last_name, salary BULK COLLECT INTO e_tab FROM plch_employees;
FOR i IN 1..e_tab.count
LOOP
dbms_output.put_line('fetch data by bulk: ' || e_tab(i).last_name || ' ' || e_tab(i).salary);
END LOOP;--fetch multiple cols with for clause
FOR eachrow IN (SELECT last_name, salary FROM plch_employees)
LOOP
dbms_output.put_line('fetch data by for: ' || eachrow.last_name || ' ' || eachrow.salary);END LOOP;END;
/
例子 DECLARE TYPE salaryTab IS TABLE OF plch_employees.salary%TYPE; s_tab salaryTab; TYPE eTab IS RECORD ( last_name plch_employees.last_name%TYPE, salary plch_employees.salary%TYPE );