CREATE TABLE employees AS SELECT * FROM hr.employees
Table created.
EXECUTE IMMEDIATE with BULK COLLECT
DECLARE
TYPE employee_ntt IS TABLE OF employees%ROWTYPE;
l_employees employee_ntt;
BEGIN
EXECUTE IMMEDIATE 'SELECT * FROM employees' BULK COLLECT INTO l_employees;
DBMS_OUTPUT.put_line (l_employees.COUNT);
END allrows_by;
107
Use a Cursor Variable and BULK COLLECT
DECLARE
my_cursor SYS_REFCURSOR;
TYPE employee_ntt IS TABLE OF employees%ROWTYPE;
l_employees employee_ntt;
BEGIN
OPEN my_cursor FOR 'SELECT * FROM employees';
FETCH my_cursor
BULK COLLECT INTO l_employees;
DBMS_OUTPUT.put_line (l_employees.COUNT);
CLOSE my_cursor;
END allrows_by;
107
Use Cursor Variable and BULK COLLECT with LIMIT
DECLARE
c_limit CONSTANT INTEGER := 50;
my_cursor SYS_REFCURSOR;
TYPE employee_ntt IS TABLE OF employees%ROWTYPE;
l_employees employee_ntt;
BEGIN
OPEN my_cursor FOR 'SELECT * FROM employees';
LOOP
FETCH my_cursor
BULK COLLECT INTO l_employees
LIMIT c_limit;
EXIT WHEN l_employees.COUNT = 0;
DBMS_OUTPUT.put_line (l_employees.COUNT);
END LOOP;
CLOSE my_cursor;
END allrows_by;
50
50
7