DBMS_PARALLEL_EXECUTE在不运行任务的情况下退出

时间:2018-07-01 19:46:39

标签: oracle plsql

对于大负载,我们通常倾向于并行执行它,因此Oracle包DBMS_PARALLEL_EXECUTE。在这里,我们按行使用分块。运行此命令时,我会得到

ORA-29495: invalid state for resume task

任务状态为“已取消”,块处于UNASSIGNED状态。

这是怎么回事?

declare
    l_sql varchar2(500);
    l_chunk_sql varchar2(500);
    l_task_nm varchar2(50):='k_clearance_1';
    l_try number:=0;
    l_status number;
    l_count number:=0;
begin
    select count(1)
    into l_count
    from user_parallel_execute_tasks
    where task_name=l_task_nm;

    --create task if not exist
    if l_count = 0 then
        --create task
        dbms_parallel_execute.create_task(l_task_nm);
    end if;

    --create chunk

    dbms_parallel_execute.create_chunks_by_rowid(
        task_name=>l_task_nm,
        table_owner=>'RXTEAM',
        table_name=>'RPM_STAGE_CLEARANCE_ID_FIX',
        by_row=>TRUE,
        chunk_size=>10000
    );

    l_sql := 'update XXXXXX krsc
        set krsc.lgcy_extr_tmst = sysdate
        where exists (select 1
                      from rxteam.rpm_stage_clearance_id_fix rscf
                      where rscf.rpm_stage_clearance_id=krsc.rpm_stage_clearance_id
                      and rscf.rowid between :start_id and :end_id)';

    --run task        
    dbms_parallel_execute.run_task(task_name=>l_task_nm,
        sql_stmt=>l_sql,
        language_flag=>DBMS_SQL.NATIVE,
        parallel_level=>40
    );

    l_try := 0;
    l_status := DBMS_PARALLEL_EXECUTE.task_status(l_task_nm);

    while (l_try < 2 and l_status != DBMS_PARALLEL_EXECUTE.FINISHED) 
    loop
        l_try := l_try + 1;
        DBMS_PARALLEL_EXECUTE.resume_task(l_task_nm);
        l_status := DBMS_PARALLEL_EXECUTE.task_status(l_task_nm);
    end loop;

    --dbms_parallel_execute.drop_task(l_task_nm)
end;
/

1 个答案:

答案 0 :(得分:0)

就我而言,问题是我提交的PL / SQL匿名块的代码中的(解析)错误。我通过查看USER_SCHEDULER_JOB_RUN_DETAILS表来发现的。 这可能会有所帮助:

SELECT t.task_name, t.sql_stmt, d.errors
    --, d.* -- uncomment to see all job detail information
FROM user_parallel_execute_tasks t
JOIN user_scheduler_job_run_details d ON d.job_name = t.job_prefix||'_1'
WHERE t.status = 'CHUNKED'
ORDER BY t.task_name, d.job_name;