ORACLE 游标 批量提取数据 FETCH BULK COLLECT

-- Created on 4/16/2012 by 43687437

declare

-- Local variables here

i integer;

cursor count_cursor is

select ROWNUM, TABLE_NAME,'SELECT COUNT(1) FROM ' || TABLE_NAME AS "SQL_DESC"

from ALL_TABLES

WHERE OWNER = 'SYS'

AND ROWNUM <= 2

ORDER BY TABLE_NAME;

TYPE COUNT_SQL IS TABLE OF count_cursor%rowtype;

CUR_COUNT COUNT_SQL;

SQL_EXECUTE VARCHAR2(200);

TABLE_NAME VARCHAR2(50);

temp integer;

begin

-- Test statements here

/*i := 1;

FOR i in 1 .. 5 loop

dbms_output.put_line('i=' || i);

end loop;*/

OPEN count_cursor;

LOOP

FETCH count_cursor BULK COLLECT

INTO CUR_COUNT LIMIT 3;

FOR i in 1 .. CUR_COUNT.COUNT LOOP

SQL_EXECUTE := CUR_COUNT(i).SQL_DESC;

TABLE_NAME := CUR_COUNT(i).TABLE_NAME;

dbms_output.put_line('SQL_DESC=' || SQL_EXECUTE);

EXECUTE IMMEDIATE SQL_EXECUTE INTO temp;

dbms_output.put_line(TABLE_NAME ||' '|| temp);

END LOOP;

EXIT WHEN count_cursor %NOTFOUND;

END LOOP;

CLOSE count_cursor;

end;

你可能感兴趣的:(oracle,sql,table,variables)