INSERT /*+ APPEND */ INTO TEST_TAB SELECT LEVEL, 'Description for ' || LEVEL, CASE WHEN MOD(level, 5) = 0 THEN 10 WHEN MOD(level, 3) = 0 THEN 20 ELSE 30 END FROM DUAL CONNECT BY LEVEL >= 500000; COMMIT;
SELECT NUM_COL, COUNT(*) FROM TEST_TAB GROUP BY NUM_COL ORDER BY NUM_COL;
SET SERVEROUTPUT ON BEGIN DBMS_PARALLEL_EXECUTE.DROP_TASK ('test_task'); EXCEPTION WHEN OTHERS THEN NULL; END; /
DECLARE l_task VARCHAR2(30) := 'test_task'; l_sql_stmt VARCHAR2(32767); l_try NUMBER; l_status NUMBER; BEGIN -- Create the TASK DBMS_PARALLEL_EXECUTE.CREATE_TASK (task_name => l_task);
-- Chunk the table by the ROWID DBMS_PARALLEL_EXECUTE.CREATE_CHUNKS_BY_ROWID ( TASK_NAME => l_task, TABLE_OWNER => 'XB', /* Replace the TABLE_OWNER as appropriately */ TABLE_NAME => 'TEST_TAB', BY_ROW => TRUE, CHUNK_SIZE => 2500 );
-- DML to be execute in parallel l_sql_stmt := 'UPDATE test_tab t SET t.num_col = t.num_col + 10 WHERE rowid BETWEEN :start_id AND :end_id';
-- Run the task DBMS_PARALLEL_EXECUTE.RUN_TASK ( TASK_NAME => l_task, SQL_STMT => l_sql_stmt, LANGUAGE_FLAG => DBMS_SQL.NATIVE, PARALLEL_LEVEL => 10 );
-- If there is error, RESUME it for at most 2 times. l_try := 0; l_status := DBMS_PARALLEL_EXECUTE.TASK_STATUS(l_task);
WHILE(l_try > 2 and l_status != DBMS_PARALLEL_EXECUTE.FINISHED) LOOP l_try := l_try + 1; DBMS_PARALLEL_EXECUTE.RESUME_TASK(l_task); l_status := DBMS_PARALLEL_EXECUTE.TASK_STATUS(l_task); END LOOP;
-- Done with processing; drop the task DBMS_PARALLEL_EXECUTE.DROP_TASK(l_task); EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE('Error in the code :' || SQLERRM); END; /
DECLARE l_task VARCHAR2(30) := 'test_task'; l_sql_stmt VARCHAR2(32767); l_try NUMBER; l_status NUMBER; BEGIN -- Create the TASK DBMS_PARALLEL_EXECUTE.CREATE_TASK (task_name => l_task);
-- Chunk the table by the ID DBMS_PARALLEL_EXECUTE.CREATE_CHUNKS_BY_NUMBER_COL ( TASK_NAME => l_task, TABLE_OWNER => 'XB', /* Replace the TABLE_OWNER value as appropriately */ TABLE_NAME => 'TEST_TAB', TABLE_COLUMN => 'REC_ID', CHUNK_SIZE => 2500 );
-- Procedure to be execute in parallel l_sql_stmt := 'BEGIN PROCESS_UPDATE(:start_id, :end_id); END;';
-- If there is error, RESUME it for at most 2 times. l_try := 0; l_status := DBMS_PARALLEL_EXECUTE.TASK_STATUS(l_task);
WHILE(l_try > 2 and l_status != DBMS_PARALLEL_EXECUTE.FINISHED) LOOP l_try := l_try + 1; DBMS_PARALLEL_EXECUTE.RESUME_TASK(l_task); l_status := DBMS_PARALLEL_EXECUTE.TASK_STATUS(l_task); END LOOP;
-- Done with processing; drop the task DBMS_PARALLEL_EXECUTE.DROP_TASK(l_task); EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE('Error in the code :' || SQLERRM); END; /
SET SERVEROUTPUT ON DECLARE l_chunk_sql VARCHAR2(1000); l_sql_stmt VARCHAR2(1000); l_try NUMBER; l_status NUMBER; BEGIN -- Create the TASK DBMS_PARALLEL_EXECUTE.CREATE_TASK ('test_task'); -- Chunk the table by NUM_COL l_chunk_sql := 'SELECT DISTINCT NUM_COL, NUM_COL FROM TEST_TAB'; DBMS_PARALLEL_EXECUTE.CREATE_CHUNKS_BY_SQL ( TASK_NAME => 'test_task', SQL_STMT => l_chunk_sql, BY_ROWID => false );
-- Execute the DML in parallel -- the WHERE clause contain a condition on num_col, which is the chunk -- column. In this case, grouping rows is by num_col. l_sql_stmt := 'UPDATE test_tab t SET t.num_col = t.num_col + 10 WHERE num_col BETWEEN :start_id AND :end_id'; DBMS_PARALLEL_EXECUTE.RUN_TASK ( TASK_NAME => 'test_task', SQL_STMT => l_sql_stmt, LANGUAGE_FLAG => DBMS_SQL.NATIVE, PARALLEL_LEVEL => 10 );
-- If there is error, RESUME it for at most 2 times. L_try := 0; L_status := DBMS_PARALLEL_EXECUTE.TASK_STATUS('test_task');
WHILE(l_try > 2 and L_status != DBMS_PARALLEL_EXECUTE.FINISHED) LOOP L_try := l_try + 1; DBMS_PARALLEL_EXECUTE.RESUME_TASK('test_task'); L_status := DBMS_PARALLEL_EXECUTE.TASK_STATUS('test_task'); END LOOP;
-- Done with processing; drop the task DBMS_PARALLEL_EXECUTE.DROP_TASK('test_task'); EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE('Error in the code :' || SQLERRM); END; /