之前写过一篇bulk collect的博文,只是对于bulk collect做了简单的实例。http://blog.itpub.net/23718752/viewspace-1289696/pl/sql中的forall简单测试(r5笔记第63天)而forall却是相反,是提供一次上下文切换,会在forall的过程中进行数据的包装处理。一次发送给sql执行器去处理,大大减少了上下文切换时间。pl/sql中的forall简单测试(r5笔记第63天)对于此,可以想象,如果cursor中的结果集很庞大,就很可能进行大量的上下文切换,导致执行速度骤降。[email protected]> create unique index inx_test_data_pk on test_data(object_id);Index created.Elapsed: 00:00:00.48[[email protected] plsql]$ cat a.sqlcreate or replace procedure test_proc as cursor test_cur is select *from test_data; i number;begin i:=1; for cur in test_cur loop update test_data set object_name=cur.object_namewhere object_id=cur.object_id; dbms_output.put_line('this is a test'); i:=i+1; end loop;end;/Elapsed: 00:00:13.73[[email protected] plsql]$ cat b.sqlcreate or replace procedure test_proc as cursor test_cur is select *from test_data; type rec_type is table of test_cur%rowtype index by binary_integer; recs rec_type;begin open test_cur; fetch test_cur bulk collect into recs; close test_cur; forall i in 1..recs.COUNT update test_data set object_name=recs(i).object_namewhere object_id=recs(i).object_id; dbms_output.put_line('this is a test');end;/[email protected]> exec test_proc;this is a testPL/SQL procedure successfully completed.Elapsed: 00:00:01.67

相关文章:

  • 2021-11-30
  • 2021-11-22
  • 2021-06-22
  • 2021-10-08
  • 2021-09-15
  • 2021-06-05
  • 2021-06-27
  • 2022-01-05
猜你喜欢
  • 2021-09-02
  • 2021-11-23
  • 2021-06-30
  • 2022-01-06
  • 2021-12-10
  • 2021-07-21
  • 2021-08-08
相关资源
相似解决方案