DBMS_PARALLEL_EXECUTEThe DBMS_PARALLEL_EXECUTE

[复制链接]
查看11 | 回复6 | 2012-5-21 10:19:41 | 显示全部楼层 |阅读模式
DBMS_PARALLEL_EXECUTEThe DBMS_PARALLEL_EXECUTE package enables the user to incrementally update table data in parallel.
See Also:Oracle Database Advanced Application Developer's Guide
Oracle Database Reference

This chapter contains the following topics:
Using DBMS_PARALLEL_EXECUTE
Overview
Security Model
Constants
Views
Exceptions
Examples
Summary of DBMS_PARALLEL_EXECUTE Subprograms
Using DBMS_PARALLEL_EXECUTEOverview
Security Model
Constants
Views
Exceptions
Examples
OverviewThis package enables the user to incrementally update table data in parallel, in two high level steps:
Group sets of rows in the table into smaller sized chunks.
Run a user specified statement on these chunks in parallel, and commit when finished processing each chunk.
This package introduces the notion of parallel execution task. This task groups the various steps associated with the parallel execution of a PL/SQL block, which is typically updating table data.
All of the package subroutines (except the GENERATE_TASK_NAME Function and the TASK_STATUS Procedure) perform a commit.
Security ModelDBMS_PARALLEL_EXECUTE is a SYS-owned package which is granted to PUBLIC.
Any user can create or operate his own parallel execution tasks and access the USER view.
Users who have the ADM_PARALLEL_EXECUTE_TASK role can perform administrative routines (qualified by the prefix ADM_) and access the DBA view.
Apart from the administrative routines, all the subprograms refer to tasks owned by the current user.
To execute chunks in parallel, the user must have CREATE JOB system privilege.
The CHUNK_BY_SQL, RUN_TASK, and RESUME_TASK subprograms require a query, and are executed using DBMS_SQL. Invokers of the DBMS_SQL interface must ensure that none of the queries passed-in contains SQL injection.
ConstantsThe DBMS_PARALLEL_EXECUTE package uses the constants shown in following tables:
Table 98-1, "DBMS_PARALLEL_EXECUTE Constants - Chunk Status Value"
Table 98-2, "DBMS_PARALLEL_EXECUTE Constants - Task Status Value"
Table 98-1 DBMS_PARALLEL_EXECUTE Constants - Chunk Status ValueConstantTypeValueDescription
ASSIGNED
NUMBER
1
Chunk has been assigned for processing
PROCESSED
NUMBER
2
Chunk has been processed successfully
PROCESSED_WITH_ERROR
NUMBER
3
Chunk has been processed, but an error occurred during processing
UNASSIGNED
NUMBER
0
Chunk is unassigned

Table 98-2 DBMS_PARALLEL_EXECUTE Constants - Task Status ValueConstantTypeValueDescription
CHUNKED
NUMBER
4
Table associated with the task has been chunked, but none of the chunk has been assigned for processing
CHUNKING
NUMBER
2
Table associated with the task is being chunked
CHUNKING_FAILED
NUMBER
3
Chunking failed
CRASHED
NUMBER
8
Only applicable if parallel execution is used, this occurs if a job slave crashes or if the database crashes during EXECUTE, leaving a chunk in ASSIGNED or UNASSIGNED state.
CREATED
NUMBER
1
The task has been created by the CREATE_TASK Procedure
FINISHED
NUMBER
6
All chunks processed without error
FINISHED_WITH_ERROR
NUMBER
7
All chunks processed, but with errors in some cases
PROCESSING
NUMBER
5
Part of the chunk assigned for processing, or which has been processed

ViewsThe DBMS_PARALLEL_EXECUTE package uses views listed in the Oracle Database Reference:
DBA_PARALLEL_EXECUTE_CHUNKS
DBA_PARALLEL_EXECUTE_TASKS
USER_PARALLEL_EXECUTE_CHUNKS
USER_PARALLEL_EXECUTE_TASKS
ExceptionsThe following table lists the exceptions raised by DBMS_PARALLEL_EXECUTE.
Table 98-3 Exceptions Raised by DBMS_PARALLEL_EXECUTEExceptionError CodeDescription
CHUNK_NOT_FOUND
29499
Specified chunk does not exist
DUPLICATE_TASK_NAME
29497
Same task name has been used by an existing task
INVALID_STATE_FOR_CHUNK
29492
Attempts to chunk a table that is not in CREATED or CHUNKING_FAILED state
INVALID_STATE_FOR_REDSUME
29495
Attempts to resume execution, but the task is not in FINISHED_WITH_ERROR or CRASHED state
INVALID_STATE_FOR_RUN
29494
Attempts to execute the task that is not in CHUNKED state
INVALID_STATUS
29493
Attempts to set an invalid value to the chunk status
INVALID_TABLE
29491
Attempts to chunk a table by rowid in cases in which the table is not a physical table, or the table is an IOT
MISSING_ROLE
29490
User does not have the necessary ADM_PARALLEL_EXECUTE role
TASK_NOT_FOUND
29498
Specified task_name does not exist

ExamplesThe following examples run on the Human Resources (HR) schema of the Oracle Database Sample Schemas. It requires that the HR schema be created with the JOB SYSTEM privilege.
Chunk by ROWIDThis example shows the most common usage of this package. After calling the RUN_TASK Procedure, it checks for errors and re-runs in the case of error.
DECLAREl_sql_stmt VARCHAR2(1000);l_try NUMBER;l_status NUMBER;BEGIN -- Create the TASKDBMS_PARALLEL_EXECUTE.CREATE_TASK ('mytask'); -- Chunk the table by ROWIDDBMS_PARALLEL_EXECUTE.CREATE_CHUNKS_BY_ROWID('mytask', 'HR', 'EMPLOYEES', true, 100); -- Execute the DML in parallell_sql_stmt := 'update /*+ ROWID (dda) */ EMPLOYEES e SET e.salary = e.salary + 10WHERE 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_try10); -- If there is error, RESUME it for at most 2 times.L_try := 0;L_status := DBMS_PARALLEL_EXECUTE.TASK_STATUS('mytask');WHILE(l_try >LOOP---- Get a chunk to process; if there is nothing to process, then exit the -- loop;--DBMS_PARALLEL_EXECUTE.GET_ROWID_CHUNK('mytask',
l_chunk_id,
l_start_rowid,
l_end_rowid,
l_any_rows);IF (l_any_rows = false) THEN EXIT; END IF; ---- The chunk is specified by start_id and end_id.-- Bind the start_id and end_id and then execute it---- If no error occured, set the chunk status to PROCESSED.---- Catch any exception. If an exception occured, store the error num/msg-- into the chunk table and then continue to process the next chunk.-- BEGINEXECUTE IMMEDIATE l_sql_stmt using l_start_rowid, l_end_rowid;DBMS_PARALLEL_EXECUTE.SET_CHUNK_STATUS('mytask',l_chunk_id,
DBMS_PARALLEL_EXECUTE.PROCESSED);EXCEPTION WHEN OTHERS THENDBMS_PARALLEL_EXECUTE.SET_CHUNK_STATUS('mytask', l_chunk_id,
DBMS_PARALLEL_EXECUTE.PROCESSED_WITH_ERROR, SQLCODE, SQLERRM);END; ---- Finished processing one chunk; Commit here--COMMIT;END LOOP;
Summary of DBMS_PARALLEL_EXECUTE SubprogramsTable 98-4 DBMS_PARALLEL_EXECUTE Package SubprogramsSubprogramDescription
ADM_DROP_CHUNKS Procedure
Drops all chunks of the specified task owned by the specified owner
ADM_DROP_TASK Procedure
Drops the task of the given user and all related chunks
ADM_TASK_STATUS Procedure
Returns the task status
ADM_STOP_TASK Procedure
Stops the task of the given owner and related job slaves
CREATE_TASK Procedure
Creates a task for the current user
CREATE_CHUNKS_BY_NUMBER_COL Procedure
Chunks the table associated with the given task by the specified column.
CREATE_CHUNKS_BY_ROWID Procedure
Chunks the table associated with the given task by ROWID
CREATE_CHUNKS_BY_SQL Procedure
Chunks the table associated with the given task by means of a user-provided SELECT statement
DROP_TASK Procedure
Drops the task and all related chunks
DROP_CHUNKS Procedure
Drops the task's chunks
GENERATE_TASK_NAME Function
Returns a unique name for a task
GET_NUMBER_COL_CHUNK Procedure
Picks an unassigned NUMBER chunk and changes it to ASSIGNED
GET_ROWID_CHUNK Procedure
Picks an unassigned ROWID chunk and changes it to ASSIGNED
PURGE_PROCESSED_CHUNKS Procedure
Deletes all the processed chunks whose status is PROCESSED or PROCESSED_WITH_ERROR
RESUME_TASK Procedures
Retries the given the task if the RUN_TASK Procedure finished with error, or resumes the task if a crash has occurred.
RUN_TASK Procedure
Executes the specified SQL statement on the chunks in parallel
SET_CHUNK_STATUS Procedure
Sets the status of the chunk
STOP_TASK Procedure
Stops the task and related job slaves
TASK_STATUS Procedure
Returns the task status

ADM_DROP_CHUNKS ProcedureThis procedure drops all chunks of the specified task owned by the specified owner.
SyntaxDBMS_PARALLEL_EXECUTE.ADM_DROP_CHUNKS ( task_ownerINVARCHAR2, task_name INVARCHAR2);ParametersTable 98-5 ADM_DROP_CHUNKS Procedure ParametersParameterDescription
task_owner
Owner of the task
task_name
Name of the task

ADM_DROP_TASK ProcedureThis procedure drops the task of the specified user and all related chunks.
SyntaxDBMS_PARALLEL_EXECUTE.ADM_DROP_TASK ( task_ownerINVARCHAR2, task_name INVARCHAR2);ParametersTable 98-6 ADM_DROP_TASK Procedure ParametersParameterDescription
task_owner
Owner of the task
task_name
Name of the task

ADM_TASK_STATUS ProcedureThis function returns the task status.
SyntaxDBMS_PARALLEL_EXECUTE.ADM_TASK_STATUS( task_ownerINVARCHAR2, task_name INVARCHAR2) RETURN NUMBER;ParametersTable 98-7 ADM_TASK_STATUS Function ParametersParameterDescription
task_owner
Owner of the task
task_name
Name of the task

ADM_STOP_TASK ProcedureThis procedure stops the task of the specified owner and related job slaves.
SyntaxDBMS_PARALLEL_EXECUTE.ADM_STOP_TASK ( task_ownerINVARCHAR2, task_name INVARCHAR2);ParametersTable 98-8 ADM_STOP_TASK Procedure ParametersParameterDescription
task_owner
Owner of the task
task_name
Name of the task

CREATE_TASK ProcedureThis procedure creates a task for the current user. The pairing of task_name and current_user must be unique.
SyntaxDBMS_PARALLEL_EXECUTE.CREATE_TASK ( task_nameIN VARCHAR2, comment
IN VARCHAR2 DEFAULT NULL);ParametersTable 98-9 CREATE_TASK Procedure ParametersParameterDescription
task_name
Name of the task. The task_name can be any string in which related length must be less than or equal to 128 bytes.
comment
Comment field. The comment must be less than 4000 bytes.

CREATE_CHUNKS_BY_NUMBER_COL ProcedureThis procedure chunks the table (associated with the specified task) by the specified column. The specified column must be a NUMBER column. This procedure takes the MIN and MAX value of the column, and then divide the range evenly according to chunk_size. The chunks are:
START_ID
END_ID--------------------------- ---------------------------min_id_val
min_id_val+1*chunk_size-1min_id_val+1*chunk_size
min_id_val+2*chunk_size-1…
…min_id_val+i*chunk_size
max_id_valSyntaxDBMS_PARALLEL_EXECUTE.CREATE_CHUNKS_BY_NUMBER_COL ( task_name INVARCHAR2, table_owner INVARCHAR2, table_nameINVARCHAR2, table_columnINVARCHAR2, chunk_sizeINNUMBER);ParametersTable 98-10 CREATE_CHUNKS_BY_NUMBER_COL Procedure ParametersParameterDescription
task_name
Name of the task
table_owner
Owner of the table
table_name
Name of the table
table_column
Name of the NUMBER column
chunk_size
Range of each chunk

CREATE_CHUNKS_BY_ROWID ProcedureThis procedure chunks the table (associated with the specified task) by ROWID. num_row and num_block are approximate guidance for the size of each chunk. The table to be chunked must be a physical table with physical ROWID having views and table functions. Index Organized Tables are not allowed.
SyntaxDBMS_PARALLEL_EXECUTE.CREATE_CHUNKS_BY_ROWID ( task_name INVARCHAR2, table_owner INVARCHAR2, table_nameINVARCHAR2, by_rows INBOOLEAN, chunk_sizeINNUMBER);ParametersTable 98-11 CREATE_CHUNKS_BY_ROWID Procedure ParametersParameterDescription
task_name
Name of the task
table_owner
Owner of the table
table_name
Name of the table
by_rows
TRUE if chunk_size refers to the number of rows, otherwise, chunk_size refers to the number of blocks
chunk_size
Approximate number of rows/blocks to process for each commit cycle

CREATE_CHUNKS_BY_SQL ProcedureThis procedure chunks the table (associated with the specified task) by means of a user-provided SELECT statement. The select statement which returns the range of each chunk must have two columns: start_id and end_id. If task is to chunk by ROWID, then the two columns must be of ROWID type. If the task is to chunk the table by NUMBER column, then the two columns must be of NUMBER type. The procedure provides the flexibility to users who want to deploy user-defined chunk algorithms.
SyntaxDBMS_PARALLEL_EXECUTE.CREATE_CHUNKS_BY_SQL ( task_name INVARCHAR2, sql_statement INCLOB, by_rowidINBOOLEAN);ParametersTable 98-12 CREATE_CHUNKS_BY_SQL Procedure ParametersParameterDescription
task_name
Name of the task
sql_statment
SQL which returns the chunk ranges
by_rowid
TRUE if the table is chunked by rowids

DROP_TASK ProcedureThis procedure drops the task and all related chunks.
SyntaxDBMS_PARALLEL_EXECUTE.DROP_TASK ( task_name IN VARCHAR2);ParametersTable 98-13 DROP_TASK Procedure ParametersParameterDescription
task_name
Name of the task

DROP_CHUNKS ProcedureThis procedure drops the task's chunks.
SyntaxDBMS_PARALLEL_EXECUTE.DROP_CHUNKS ( task_name IN VARCHAR2);ParametersTable 98-14 DROP_CHUNKS Procedure ParametersParameterDescription
task_name
Name of the task

GENERATE_TASK_NAME FunctionThis function returns a unique name for a task. The name is of the form prefixN where N is a number from a sequence. If no prefix is specified, the generated name is, by default, be TASK$_1, TASK$_2, TASK$_3, and so on. If 'SCOTT' is specified as the prefix, the name is SCOTT1, SCOTT2, and so on.
SyntaxDBMS_PARALLEL_EXECUTE.GENERATE_TASK_NAME ( prefixINVARCHAR2 DEFAULT 'TASK$_')RETURN VARCHAR2;ParametersTable 98-15 GENERATE_TASK_NAME Function ParametersParameterDescription
prefix
The prefix to use when generating the task name

GET_NUMBER_COL_CHUNK ProcedureThis procedure picks an unassigned NUMBER chunk and changes it to ASSIGNED. If there are no more chunks to assign, any_rows is set to FALSE. Otherwise, the chunk_id, start and end_id of the chunk is returned as OUT parameters. The chunk info in DBMS_PARALLEL_EXECUTE_CHUNKS$ is updated as follows: STATUS becomes ASSIGNED; START_TIMESTAMP records the current time; END_TIMESTAMP is cleared.
See Also:Views
SyntaxDBMS_PARALLEL_EXECUTE.GET_NUMBER_COL_CHUNK ( task_name IN VARCHAR2, chunk_idOUT NUMBER, start_rowid OUT ROWID, end_id
OUT ROWID, any_rowsOUT BOOLEAN);ParametersTable 98-16 GET_NUMBER_COL_CHUNK Procedure ParametersParameterDescription
task_name
Name of the task
chunk_id
Chunk_id of the chunk
start_rowid
Start rowid in the returned range
end_id
End rowid in the returned range
any_rows
Indicating if there could be any rows to process in the range

Usage NotesIf the task is chunked by ROWID, then get_rowid_range should be used. If the task is chunked by NUMBER column, then get_number_col_range should be used. If the user makes the wrong function call, the returning chunk_id and any_rows has a valid value but start/end_(row)id is NULL.
GET_ROWID_CHUNK ProcedureThis procedure picks an unassigned ROWID chunk and changes it to ASSIGNED. If there are no more chunks to assign, any_rows is set to FALSE. Otherwise, the chunk_id, start and end_id of the chunk is returned as OUT parameters. The chunk info in DBMS_PARALLEL_EXECUTE_CHUNKS$ is updated as follows: STATUS becomes ASSIGNED; START_TIMESTAMP records the current time; END_TIMESTAMP is cleared.
See Also:Views
SyntaxDBMS_PARALLEL_EXECUTE.GET_ROWID_CHUNK ( task_name IN VARCHAR2, chunk_idOUT NUMBER, start_rowid OUT ROWID, end_id
OUT ROWID, any_rowsOUT BOOLEAN);ParametersTable 98-17 GET_ROWID_CHUNK Procedure ParametersParameterDescription
task_name
Name of the task
chunk_id
Chunk_id of the chunk
start_rowid
Start rowid in the returned range
end_id
End rowid in the returned range
any_rows
Indicating if there could be any rows to process in the range

Usage NotesIf the task is chunked by ROWID, then get_rowid_range should be used. If the task is chunked by NUMBER column, then get_number_col_range should be used. If the user makes the wrong function call, the returning chunk_id and any_rows still have valid value but start/end_(row)id is NULL.
PURGE_PROCESSED_CHUNKS ProcedureThis procedure deletes all the processed chunks whose status is PROCESSED or PROCESSED_WITH_ERROR.
SyntaxDBMS_PARALLEL_EXECUTE.PURGE_PROCESSED_CHUNKS ( task_name IN VARCHAR2);ParametersTable 98-18 PURGE_PROCESSED_CHUNKS Procedure ParametersParameterDescription
task_name
Name of the task

RESUME_TASK ProceduresThis procedure retries the specified the task if the RUN_TASK Procedure finished with error, or resumes the task if a crash has occurred. The user can only invoke this procedure if the task is in a CRASHED or FINISHED_WITH_ERROR state. For a crashed serial execution, the state remains in processing. The FORCE option allows user to resume any task in PROCESSING state. However, it is the user's responsibility to determine that a crash has occurred.The procedure resumes processing the chunks which have not been processed. Also, chunks which are in PROCESSED_WITH_ERROR or ASSIGNED (due to crash) state are processed because those chunks did not commit.This procedure takes the same argument as the RUN_TASK Procedure.The overload which takes task_name as the only input argument re-uses the arguments provided in the previous invoking of the RUN_TASK Procedure or RESUME_TASK Procedures.
See Also:Table 98-2, "DBMS_PARALLEL_EXECUTE Constants - Task Status Value"
SyntaxDBMS_PARALLEL_EXECUTE.RESUME_TASK ( task_name
INVARCHAR2, sql_stmt
INCLOB, language_flag
INNUMBER, edition
INVARCHAR2DEFAULT NULL, apply_crossedition_triggerINVARCHAR2DEFAULT NULL, fire_apply_trigger
INBOOLEAN DEFAULT TRUE, parallel_level
INNUMBERDEFAULT 0, job_class
INVARCHAR2DEFAULT 'DEFAULT_JOB_CLASS', force
INBOOLEAN DEFAULT FALSE);DBMS_PARALLEL_EXECUTE.RESUME_TASK ( task_name
INVARCHAR2, force
INBOOLEAN DEFAULT FALSE);ParametersTable 98-19 RESUME_TASK Procedure ParametersParameterDescription
task_name
Name of the task
sql_stmt
SQL statement; must have :start_id and :end_id placeholder
language_flag
Determines how Oracle handles the SQL statement. The following options are recognized:
V6 (or 0) specifies version 6 behavior
NATIVE (or 1) specifies normal behavior for the database to which the program is connected
V7 (or 2) specifies Oracle database version 7 behavior

edition
Specifies the edition to run the statement in. Default is the current edition.
apply_crossedition_trigger
Specifies the unqualified name of a forward crossedition trigger that is to be applied to the specified SQL. The name is resolved using the edition and current_schema setting in which the statement is to be executed. The trigger must be owned by the user who executes the statement.
fire_apply_trigger
Indicates whether the specified apply_crossedition_trigger is itself to be executed, or should only be a guide used in selecting other triggers
parallel_level
Number of parallel jobs; zero if run in serial; NULL uses the default parallelism
job_class
If running in parallel, the jobs all belong to the specified job class
force
If TRUE, do not raise an error if the status is PROCESSING.

ExamplesSuppose the chunk table contains the following chunk ranges:
START_ID
END_ID--------------------------- ---------------------------1
1011
2021
30And the specified SQL statement is:
UPDATE employeesSET salary = salary + 10WHERE e.employee_idBETWEEN :start_id AND :end_idThis procedure executes the following statements in parallel:
UPDATE employeesSET salary =.salary + 10WHERE employee_id BETWEEN 1 and 10; COMMIT;UPDATE employeesSET salary =.salary + 10WHERE employee_id between 11 and 20;COMMIT;UPDATE employeesSET salary =.salary + 10WHERE employee_id between 21 and 30;COMMIT;RUN_TASK ProcedureThis procedure executes the specified statement (sql_stmt) on the chunks in parallel. It commits after processing each chunk. The specified statement must have two placeholders called start_id, and end_id respectively, which represent the range of the chunk to be processed. The types of the placeholder must be rowid where ROWID based chunking was used, or NUMBER where number based chunking was used. The specified statement should not commit unless it is idempotent.
The SQL statement is executed as the current user.
If apply_crossedition_trigger is specified, DBMS_CROSSEDITION_TRIGGER.IS_APPLYING returns true for the sessions executing the SQL. Therefore, for parallel execution, DBMS_CROSSEDITION_TRIGGER.IS_APPLYING returns true in the Job slaves session.
Chunks can be executed in parallel by DBMS_SCHEDULER Job slaves. Therefore, parallel execution requires CREATE JOB system privilege. The Job slaves is created under the current user. The default number of Job slaves is computed as the product of Oracle parameters cpu_count and parallel_threads_per_cpu. On a Real Application Clusters installation, the number of Job slaves is the sum of individual settings on each node in the cluster. This procedure returns only when all the chunks are processed. In parallel cases, this procedure returns only when all the Job slaves finished.
SyntaxDBMS_PARALLEL_EXECUTE.RUN_TASK ( task_name
INVARCHAR2, sql_stmt
INCLOB, language_flag
INNUMBER, edition
INVARCHAR2DEFAULT NULL, apply_crossedition_triggerINVARCHAR2DEFAULT NULL, fire_apply_trigger
INBOOLEAN DEFAULT TRUE, parallel_level
INNUMBERDEFAULT 0, job_class
INVARCHAR2DEFAULT 'DEFAULT_JOB_CLASS');ParametersTable 98-20 RUN_TASK Procedure ParametersParameterDescription
task_name
Name of the task
sql_stmt
SQL statement; must have :start_id and :end_id placeholder
language_flag
Determines how Oracle handles the SQL statement. The following options are recognized:
V6 (or 0) specifies version 6 behavior
NATIVE (or 1) specifies normal behavior for the database to which the program is connected
V7 (or 2) specifies Oracle database version 7 behavior

edition
Specifies the edition to run the statement in. Default is the current edition.
apply_crossedition_trigger
Specifies the unqualified name of a forward crossedition trigger that is to be applied to the specified SQL. The name is resolved using the edition and current_schema setting in which the statement is to be executed. The trigger must be owned by the user executes the statement.
fire_apply_trigger
Indicates whether the specified apply_crossedition_trigger is itself to be executed, or should only be a guide used in selecting other triggers.
parallel_level
Number of parallel jobs; zero if run in serial; NULL uses the default parallelism.\
job_class
If running in parallel, the jobs belong to the specified job class

ExamplesSuppose the chunk table contains the following chunk ranges:
START_ID
END_ID--------------------------- ---------------------------1
1011
2021
30And the specified SQL statement is:
UPDATE employeesSET salary = salary + 10WHERE e.employee_idBETWEEN :start_id AND :end_idThis procedure executes the following statements in parallel:
UPDATE employeesSET salary =.salary + 10WHERE employee_id BETWEEN 1 and 10; COMMIT;UPDATE employeesSET salary =.salary + 10WHERE employee_id between 11 and 20;COMMIT;UPDATE employeesSET salary =.salary + 10WHERE employee_id between 21 and 30;COMMIT;

回复

使用道具 举报

千问 | 2012-5-21 10:19:41 | 显示全部楼层
SET_CHUNK_STATUS ProcedureThis procedure sets the status of the chunk. The START_TIMESTAMP and END_TIMESTAMP of the chunk is updated according to the new status:
Value of the new Status
Side Effect--------------------------- ---------------------------UNASSIGNED
START_TIMESTAMP and END_TIMESTAMP
will be clearedASSIGNED
START_TIMESTAMP will be the current time
and END_TIMESTAMP will be cleared.PROCESSED or PROCESSED_WITH_ERROR The current time will be recorded
in END_TIMESTAMPSee Also:Views
SyntaxDBMS_PARALLEL_EXECUTE.SET_CHUNK_STATUS ( task_name IN VARCHAR2, chunk_idOUT NUMBER, status
INNUMBER, err_num INNUMBER DEFAULT NULL, err_msg INVARCHAR2 DEFAULT NULL);ParametersTable 98-21 SET_CHUNK_STATUS Procedure ParametersParameterDescription
task_name
Name of the task
chunk_id
Chunk_id of the chunk
status
Status of the chunk: UNASSIGNED, ASSIGNED, PROCESSED PROCESSED_WITH_ERROR
err_num
Error code returned during the processing of the chunk
err_msg
Error message returned during the processing of the chunk

STOP_TASK ProcedureThis procedure stops the task and related job slaves.
SyntaxDBMS_PARALLEL_EXECUTE.STOP_TASK ( task_name IN VARCHAR2);ParametersTable 98-22 STOP_TASK Procedure ParametersParameterDescription
task_name
Name of the task

TASK_STATUS ProcedureThis function returns the task status.
SyntaxDBMS_PARALLEL_EXECUTE.TASK_STATUS ( task_name IN VARCHAR2);ParametersTable 98-23 TASK_STATUS Procedure ParametersParameterDescription
task_name
Name of the task

回复

使用道具 举报

千问 | 2012-5-21 10:19:41 | 显示全部楼层
pub粘贴代码还是乱的
http://docs.oracle.com/cd/E14072 ... 7/d_parallel_ex.htm




d_paralle.pdf(65.63 KB, 下载次数: 8)2012-1-2 09:08 上传点击文件名下载附件

回复

使用道具 举报

千问 | 2012-5-21 10:19:41 | 显示全部楼层
上次我翻译的tom文章也提到这种人工并行的处理。Oracle还专门为这个包写了教程啊? 有中文版的吗?

回复

使用道具 举报

千问 | 2012-5-21 10:19:41 | 显示全部楼层
newkid 发表于 2012-1-2 09:56
上次我翻译的tom文章也提到这种人工并行的处理。Oracle还专门为这个包写了教程啊? 有中文版的吗?

不是教程,是参考,tom的最后1本书里也有
回复

使用道具 举报

千问 | 2012-5-21 10:19:41 | 显示全部楼层
不错的东西,研究下
回复

使用道具 举报

千问 | 2012-5-21 10:19:41 | 显示全部楼层
Chunk by ROWID
This example shows the most common usage of this package. After calling the RUN_TASK Procedure, it checks for errors and re-runs in the case of error.
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', 'HR', 'EMPLOYEES', true, 100);

-- Execute the DML in parallel
l_sql_stmt := 'update /*+ ROWID (dda) */ EMPLOYEES e
SET e.salary = e.salary + 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_try10);

-- If there is error, RESUME it for at most 2 times.
L_try := 0;
L_status := DBMS_PARALLEL_EXECUTE.TASK_STATUS('mytask');
WHILE(l_try >
LOOP
--
-- Get a chunk to process; if there is nothing to process, then exit the
-- loop;
--
DBMS_PARALLEL_EXECUTE.GET_ROWID_CHUNK('mytask',

l_chunk_id,

l_start_rowid,

l_end_rowid,

l_any_rows);
IF (l_any_rows = false) THEN EXIT; END IF;

--
-- The chunk is specified by start_id and end_id.
-- Bind the start_id and end_id and then execute it
--
-- If no error occured, set the chunk status to PROCESSED.
--
-- Catch any exception. If an exception occured, store the error num/msg
-- into the chunk table and then continue to process the next chunk.
--
BEGIN
EXECUTE IMMEDIATE l_sql_stmt using l_start_rowid, l_end_rowid;
DBMS_PARALLEL_EXECUTE.SET_CHUNK_STATUS('mytask',l_chunk_id,

DBMS_PARALLEL_EXECUTE.PROCESSED);
EXCEPTION WHEN OTHERS THEN
DBMS_PARALLEL_EXECUTE.SET_CHUNK_STATUS('mytask', l_chunk_id,

DBMS_PARALLEL_EXECUTE.PROCESSED_WITH_ERROR, SQLCODE, SQLERRM);
END;

--
-- Finished processing one chunk; Commit here
--
COMMIT;
END LOOP;

我帮你贴一下,OO
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行