DECLARE
sql_stmt_ VARCHAR2(32000);
CURSOR get_data IS
SELECT column_1,
column_2,
column_3,
column_4,
column_5
FROM some_tab
WHERE ROWNUM <= 10; -- ROWNUM is optional
-- create type using a cursor
TYPE temp_rec_type IS TABLE OF get_data%ROWTYPE INDEX BY BINARY_INTEGER;
temp_rec_ temp_rec_type;
BEGIN
-- Way 1 - Load data using normal cursor open fecth
--OPEN get_data;
--FETCH get_data BULK COLLECT INTO temp_rec_;
--CLOSE get_data;
-- Way 2 - Load data using executing sql statement via EXECUTE IMMEDIATE
sql_stmt_ := 'SELECT column_1,
column_2,
column_3,
column_4,
column_5
FROM some_tab
WHERE ROWNUM <= 10';
EXECUTE IMMEDIATE sql_stmt_ BULK COLLECT INTO temp_rec_;
-- loop of fetch data
FOR i_ IN 1..temp_rec_.COUNT LOOP
Dbms_Output.Put_Line(temp_rec_(i_).column_1 || ';' ||
temp_rec_(i_).column_2 || ';' ||
temp_rec_(i_).column_3 || ';' ||
temp_rec_(i_).column_4 || ';' ||
temp_rec_(i_).column_5 ||);
END LOOP;
END;
Useful Links:
> Bulk Processing with PL/SQL
No comments:
Post a Comment