Oracle 的 bulk collect用法
採用bulk collect可以將查詢結果一次性地載入到collections中,而不是透過cursor一條一條地處理。
可以在select into,fetch into,returning into語句使用bulk collect。
注意:在使用bulk collect時,所有的into變數都必須是collections。
create table t_test as
select object_id, object_name, object_type
from dba_objects
where wner = 'TEST';
1、在select into語句中使用bulk collect
declare
type object_list is table of t_test.object_name%type;
objs object_list;
begin
select object_name bulk collect
into objs
from t_test
where rownum <= 100;
for r in objs.first .. objs.last loop
dbms_output.put_line(' objs(r)=' || objs(r));
end loop;
end;
/
2、在fetch into中使用bulk collect
declare
type objecttab is table of t_test%rowtype;
objs objecttab;
cursor cob is
select object_id, object_name, object_type
from t_test
where rownum <= 10;
begin
open cob;
fetch cob bulk collect
into objs;
close cob;
for r in objs.first .. objs.last loop
dbms_output.put_line(' objs(r)=' || objs(r).object_name);
end loop;
end;
/
以上為把結果集一次fetch到collect中,我們還可以透過limit引數,來分批fetch資料,如下:
declare
type objecttab is table of t_test%rowtype;
objs objecttab;
cursor cob is
select object_id, object_name, object_type
from t_test
where rownum <= 10000;
begin
open cob;
loop
fetch cob bulk collect
into objs limit 1000;
exit when cob%notfound;
dbms_output.put_line('count:' || objs.count || ' first:' || objs.first ||
' last:' || objs.last);
for r in objs.first .. objs.last loop
dbms_output.put_line(' objs(r)=' || objs(r).object_name);
end loop;
end loop;
close cob;
end;
/
你可以根據實際來調整limit引數的大小,來達到最優的效能。limit引數會影響到PGA的使用率。
3、在returning into中使用bulk collect
declare
type id_list is table of t_test.object_id%type;
ids id_list;
type name_list is table of t_test.object_name%type;
names name_list;
begin
delete from t_test
where object_id <= 87510 returning object_id, object_name bulk collect into ids,
names;
dbms_output.put_line('deleted ' || sql%rowcount || ' rows:');
for i in ids.first .. ids.last loop
dbms_output.put_line('object #' || ids(i) || ': ' || names(i));
end loop;
end;
/
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9399028/viewspace-683746/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle comment on的用法Oracle
- 講透JAVA Stream的collect用法與原理,遠比你想象的更強大Java
- 7.53 COLLECT
- ORACLE SEQUENCE用法Oracle
- 【Oracle的NVL函式用法】Oracle函式
- oracle樹中prior的用法Oracle
- Go 語言中的 collect 使用Go
- oracle中的CURRVAL和NEXTVAL用法Oracle
- bulk forall 的測試(轉)
- oracle中substr() instr() 用法Oracle
- 【TUNE_ORACLE】Oracle Hint之概念與用法Oracle
- Elasticsearch——mget及bulkElasticsearch
- Oracle行列轉換及pivot子句的用法Oracle
- [轉載] Oracle:start with...connect by子句的用法Oracle
- Oracle臨時表的用法總結FLOracle
- sqlserver bulk insert報錯Cannot bulk load because the file could not be opened.SQLServer
- 用 Laravel Collect 收藏文章Laravel
- 【elasticsearch】bulk api奇特的json格式的原因ElasticsearchAPIJSON
- 非空校驗在oracle和mysql中的用法OracleMySql
- BULK In-BIND與RECORD(轉)
- mongodb批量操作, bulk_write,MongoDB
- 最新kali之bulk_extractor
- Java8之Stream-強大的collect操作Java
- Oracle批量插入資料insert all into用法Oracle
- 【SQL】Oracle查詢轉換之 OR用法SQLOracle
- oracle正規表示式regexp_like的用法詳解Oracle
- Oracle中Nextval用法SEQUENCE與SYS_GUID()OracleGUI
- How to Collect Diagnostics for Database Hanging Issues (Doc ID 452358.1)Database
- vue i18n-collect工具開發Vue
- libusb:libusb_bulk_transfer的timeout引數問題
- How to open and close static streams in a USB bulk endpoint
- Oracle minus用法詳解及應用例項Oracle
- oracle中listagg()和wmsys.wm_concat()基本用法Oracle
- Script to Collect Log File Sync Diagnostic Information (lfsdiag.sql)ORMSQL
- oracle資料庫常用分析函式與聚合函式的用法Oracle資料庫函式
- Bulk 異常引發的 Elasticsearch 記憶體洩漏Elasticsearch記憶體
- 一個用於文章收藏的擴充套件包 Laravel-Collect套件Laravel
- ElasticSearch7.4批量匯入_bulkElasticsearch
- Signac處理bulk ATAC-seq資料