這篇文章將為大家詳細講解有關Oracle11.2中怎樣使用DBMS_PARALLEL_EXECUTE包實現(xiàn)并行,文章內容質量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關知識有一定的了解。
創(chuàng)新互聯(lián)建站主要從事網(wǎng)站設計制作、成都網(wǎng)站制作、網(wǎng)頁設計、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務。立足成都服務祁縣,十余年網(wǎng)站建設經(jīng)驗,價格優(yōu)惠、服務專業(yè),歡迎來電咨詢建站服務:18982081108
使用DBMS_PARALLEL_EXECUTE包實現(xiàn)并行
該包支持insert、update、delete、merge、匿名包自動以scheduler job 方式并行執(zhí)行。
支持的chunk方式包括:
CREATE_CHUNKS_BY_NUMBER_COL Procedure
CREATE_CHUNKS_BY_ROWID Procedure
CREATE_CHUNKS_BY_SQL Procedure
測試:
SQL> create table employees
2 as
3 select * from dba_objects;
Table created
SQL> select count(*) from mh.employees;
COUNT(*)
----------
72787
SQL>
SQL> select count(*) from mh.employees where object_id=data_object_id;
COUNT(*)
----------
7253
DECLARE
l_sql_stmt VARCHAR2(1000);
l_try NUMBER;
l_status NUMBER;
BEGIN
-- Create the TASK
DBMS_PARALLEL_EXECUTE.CREATE_TASK ('mytask');
-- Chunk the table by ROWID
DBMS_PARALLEL_EXECUTE.CREATE_CHUNKS_BY_ROWID('mytask', 'MH', 'EMPLOYEES', true, 100);
-- Execute the DML in parallel
l_sql_stmt := 'update /*+ ROWID (dda) */ EMPLOYEES e
SET e.object_id = e.object_id + 10
WHERE rowid BETWEEN :start_id AND :end_id';
DBMS_PARALLEL_EXECUTE.RUN_TASK('mytask', l_sql_stmt, DBMS_SQL.NATIVE,
parallel_level => 10);
-- If there is an error, RESUME it for at most 2 times.
L_try := 0;
L_status := DBMS_PARALLEL_EXECUTE.TASK_STATUS('mytask');
WHILE(l_try < 2 and L_status != DBMS_PARALLEL_EXECUTE.FINISHED)
LOOP
L_try := l_try + 1;
DBMS_PARALLEL_EXECUTE.RESUME_TASK('mytask');
L_status := DBMS_PARALLEL_EXECUTE.TASK_STATUS('mytask');
END LOOP;
-- Done with processing; drop the task
DBMS_PARALLEL_EXECUTE.DROP_TASK('mytask');
END;
/
執(zhí)行期間在另一個session中查詢:
Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.1.0
Connected as mh@boclink
SQL>
SQL> select * from user_parallel_execute_chunks;
CHUNK_ID TASK_NAME STATUS START_ROWID END_ROWID START_TS END_TS
-------- --------- ---------- ------------------ ------------------ - ------------------- -------------------
1 mytask PROCESSED AAAVBvAAGAAAAEgAAA AAAVBvAAGAAAAEnCcP 05-1月 -14 02.27.39 05-1月 -14 02.27.39
2 mytask PROCESSED AAAVBvAAGAAAAEoAAA AAAVBvAAGAAAAEvCcP 05-1月 -14 02.27.39 05-1月 -14 02.27.39
3 mytask PROCESSED AAAVBvAAGAAAAEwAAA AAAVBvAAGAAAAE3CcP 05-1月 -14 02.27.39 05-1月 -14 02.27.39
4 mytask PROCESSED AAAVBvAAGAAAAE4AAA AAAVBvAAGAAAAE/CcP 05-1月 -14 02.27.39 05-1月 -14 02.27.39
5 mytask PROCESSED AAAVBvAAGAAAAFAAAA AAAVBvAAGAAAAFHCcP 05-1月 -14 02.27.39 05-1月 -14 02.27.39
6 mytask PROCESSED AAAVBvAAGAAAAFIAAA AAAVBvAAGAAAAFPCcP 05-1月 -14 02.27.39 05-1月 -14 02.27.39
7 mytask PROCESSED AAAVBvAAGAAAAFQAAA AAAVBvAAGAAAAFXCcP 05-1月 -14 02.27.39 05-1月 -14 02.27.39
8 mytask PROCESSED AAAVBvAAGAAAAFYAAA AAAVBvAAGAAAAFfCcP 05-1月 -14 02.27.39 05-1月 -14 02.27.39
9 mytask PROCESSED AAAVBvAAGAAAAFgAAA AAAVBvAAGAAAAFnCcP 05-1月 -14 02.27.39 05-1月 -14 02.27.39
10 mytask PROCESSED AAAVBvAAGAAAAFoAAA AAAVBvAAGAAAAFvCcP 05-1月 -14 02.27.39 05-1月 -14 02.27.39
11 mytask PROCESSED AAAVBvAAGAAAAFwAAA AAAVBvAAGAAAAF3CcP 05-1月 -14 02.27.39 05-1月 -14 02.27.39
12 mytask PROCESSED AAAVBvAAGAAAAF4AAA AAAVBvAAGAAAAF/CcP 05-1月 -14 02.27.39 05-1月 -14 02.27.39
13 mytask PROCESSED AAAVBvAAGAAAAGAAAA AAAVBvAAGAAAAGHCcP 05-1月 -14 02.27.39 05-1月 -14 02.27.39
14 mytask PROCESSED AAAVBvAAGAAAAGIAAA AAAVBvAAGAAAAGPCcP 05-1月 -14 02.27.39 05-1月 -14 02.27.39
15 mytask PROCESSED AAAVBvAAGAAAAGQAAA AAAVBvAAGAAAAGXCcP 05-1月 -14 02.27.39 05-1月 -14 02.27.39
16 mytask PROCESSED AAAVBvAAGAAAAGYAAA AAAVBvAAGAAAAGfCcP 05-1月 -14 02.27.39 05-1月 -14 02.27.39
17 mytask PROCESSED AAAVBvAAGAAAAIAAAA AAAVBvAAGAAAAIxCcP 05-1月 -14 02.27.39 05-1月 -14 02.27.39
18 mytask PROCESSED AAAVBvAAGAAAAIyAAA AAAVBvAAGAAAAJjCcP 05-1月 -14 02.27.39 05-1月 -14 02.27.39
19 mytask PROCESSED AAAVBvAAGAAAAJkAAA AAAVBvAAGAAAAJ/CcP 05-1月 -14 02.27.39 05-1月 -14 02.27.39
20 mytask PROCESSED AAAVBvAAGAAAAKAAAA AAAVBvAAGAAAAKxCcP 05-1月 -14 02.27.39 05-1月 -14 02.27.39
21 mytask PROCESSED AAAVBvAAGAAAAKyAAA AAAVBvAAGAAAALjCcP 05-1月 -14 02.27.39 05-1月 -14 02.27.40
22 mytask PROCESSED AAAVBvAAGAAAALkAAA AAAVBvAAGAAAAL/CcP 05-1月 -14 02.27.39 05-1月 -14 02.27.39
23 mytask PROCESSED AAAVBvAAGAAAAMAAAA AAAVBvAAGAAAAMxCcP 05-1月 -14 02.27.39 05-1月 -14 02.27.40
24 mytask PROCESSED AAAVBvAAGAAAAMyAAA AAAVBvAAGAAAANjCcP 05-1月 -14 02.27.40 05-1月 -14 02.27.40
25 mytask PROCESSED AAAVBvAAGAAAANkAAA AAAVBvAAGAAAAN/CcP 05-1月 -14 02.27.40 05-1月 -14 02.27.40
26 mytask PROCESSED AAAVBvAAGAAAAOAAAA AAAVBvAAGAAAAOxCcP 05-1月 -14 02.27.40 05-1月 -14 02.27.40
27 mytask PROCESSED AAAVBvAAGAAAAOyAAA AAAVBvAAGAAAAPjCcP 05-1月 -14 02.27.40 05-1月 -14 02.27.40
28 mytask PROCESSED AAAVBvAAGAAAAPkAAA AAAVBvAAGAAAAP/CcP 05-1月 -14 02.27.40 05-1月 -14 02.27.40
29 mytask PROCESSED AAAVBvAAGAAAAQAAAA AAAVBvAAGAAAAQxCcP 05-1月 -14 02.27.40 05-1月 -14 02.27.40
30 mytask PROCESSED AAAVBvAAGAAAAQyAAA AAAVBvAAGAAAARjCcP 05-1月 -14 02.27.40 05-1月 -14 02.27.40
31 mytask PROCESSED AAAVBvAAGAAAARkAAA AAAVBvAAGAAAAR/CcP 05-1月 -14 02.27.40 05-1月 -14 02.27.40
32 mytask PROCESSED AAAVBvAAGAAAASAAAA AAAVBvAAGAAAASxCcP 05-1月 -14 02.27.40 05-1月 -14 02.27.40
33 mytask PROCESSED AAAVBvAAGAAAASyAAA AAAVBvAAGAAAATjCcP 05-1月 -14 02.27.40 05-1月 -14 02.27.40
34 mytask PROCESSED AAAVBvAAGAAAATkAAA AAAVBvAAGAAAAT/CcP 05-1月 -14 02.27.40 05-1月 -14 02.27.40
35 mytask PROCESSED AAAVBvAAGAAAAUAAAA AAAVBvAAGAAAAUxCcP 05-1月 -14 02.27.40 05-1月 -14 02.27.40
36 mytask PROCESSED AAAVBvAAGAAAAUyAAA AAAVBvAAGAAAAVjCcP 05-1月 -14 02.27.40 05-1月 -14 02.27.40
37 mytask PROCESSED AAAVBvAAGAAAAVkAAA AAAVBvAAGAAAAV/CcP 05-1月 -14 02.27.40 05-1月 -14 02.27.40
38 mytask PROCESSED AAAVBvAAGAAAAWAAAA AAAVBvAAGAAAAWxCcP 05-1月 -14 02.27.40 05-1月 -14 02.27.40
39 mytask PROCESSED AAAVBvAAGAAAAWyAAA AAAVBvAAGAAAAXjCcP 05-1月 -14 02.27.40 05-1月 -14 02.27.40
40 mytask PROCESSED AAAVBvAAGAAAAXkAAA AAAVBvAAGAAAAX/CcP 05-1月 -14 02.27.40 05-1月 -14 02.27.40
40 rows selected
SQL>
SQL> select * from user_parallel_execute_tasks;
TASK_NAME CHUNK_TYPE STATUS TABLE_OWNER TABLE_NAME JOB_PREFIX LANGUAGE_FLAG EDITION FIRE_APPLY_TRIGGER PARALLEL_LEVEL JOB_CLASS
--------- ------------ --------- ------------ ----------- ---------- ------------- -------- ------------------ -------------- ------------------------------
mytask ROWID_RANGE FINISHED MH EMPLOYEES TASK$_506 1 ORA$BASE TRUE 10 DEFAULT_JOB_CLASS
SET e.object_id = e.object_id + 10
執(zhí)行結束后:
SQL> select count(*) from mh.employees where object_id=data_object_id;
COUNT(*)
----------
1
SQL> select * from user_parallel_execute_tasks;
TASK_NAME CHUNK_TYPE STATUS TABLE_OWNER TABLE_NAME JOB_PREFIX LANGUAGE_FLAG EDITION FIRE_APPLY_TRIGGER PARALLEL_LEVEL JOB_CLASS
--------- ------------ --------- ------------ ----------- ---------- ------------- -------- ------------------ -------------- ------------------------------
SQL>
SQL> select * from user_parallel_execute_chunks;
CHUNK_ID TASK_NAME STATUS START_ROWID END_ROWID START_TS END_TS
-------- --------- ---------- ------------------ ------------------ - ------------------- -------------------
SQL>
關于Oracle11.2中怎樣使用DBMS_PARALLEL_EXECUTE包實現(xiàn)并行就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
本文標題:Oracle11.2中怎樣使用DBMS_PARALLEL_EXECUTE包實現(xiàn)并行
標題來源:http://www.rwnh.cn/article4/psjcie.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供自適應網(wǎng)站、品牌網(wǎng)站建設、定制網(wǎng)站、商城網(wǎng)站、微信小程序、靜態(tài)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)