我在我的程序中有一个类似下面的示例查询:
result_rec mypkg.mytype;
OPEN CUR1 FOR
select col1, col2, col3 from table1 where something = 'a'; --rows will always be 50
LOOP
FETCH CUR1
INTO myrectype;
EXIT WHEN CUR1%NOTFOUND;
result_rec.col1 := myrectype.col1;
result_rec.col2 := myrectype.col2;
result_rec.col3 := myrectype.col3;
PIPE ROW (result_rec);
END LOOP;
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,每次我循环50次.有一个更好的方法吗?像BULK COLLECT INTO这样的东西?我该如何实现呢?
在Oracle 10g(可能是9i)中,Oracle将自动批量收集隐式游标.所以代码如下:
DECLARE
result_rec mypkg.mytype;
BEGIN
for i in (select col1, co2, col3 from table1 where something = 'a')
loop
result_rec.col1 := i.col1;
result_rec.col2 := i.col2;
result_rec.col3 := i.col3;
pipe_row (result_rec);
end loop;
END;
Run Code Online (Sandbox Code Playgroud)
只会将上下文从PL/SQL引擎切换到SQL引擎,以便每100行获取一次记录.在SQL trace(dbms_monitor.session_trace_enable())下运行它,看看!
| 归档时间: |
|
| 查看次数: |
14422 次 |
| 最近记录: |