How to create a job, when job_action need to call a procedure having CLOB parameter

这一生的挚爱 提交于 2019-12-13 03:50:28

问题


I have a procedure which is being called at server side and I need to make it asynchronous.

So I have created another proc in which I'll create Oracle'Job and this will call that proc in its job_action. Proc is:

  PROCEDURE upload_csv_file_data(a_what_to_do IN VARCHAR2,
                             a_logon_user IN VARCHAR2,
                             a_csv_data IN CLOB)
  IS
    v_job_action  VARCHAR2(32676);
    /*v_log_error   VARCHAR2(32676);*/
    v_job_name    VARCHAR2(100);
  BEGIN

    v_job_action := 'process_csv_file_data(''' || a_what_to_do || ''',''' || a_logon_user || ''',' || a_csv_data || ');';
    v_job_name    := 'UPLOAD_CSV_FILE_DATA';



    sys.dbms_scheduler.create_job(
        job_name => v_job_name,
        job_type => 'PLSQL_BLOCK',
        job_action => 'begin ' || v_job_action || ' EXCEPTION WHEN OTHERS THEN NULL; end;',
        start_date => SYSTIMESTAMP,
        job_class => 'BATCH_CLASS',
        comments => 'Start uplaoding CSV file data.',
        auto_drop => TRUE,
        enabled => TRUE);

  END;

Proc which needs to be called IN JOB is:

    CREATE OR REPLACE PROCEDURE process_csv_file_data(a_what_to_do IN VARCHAR2,
                                 a_logon_user IN VARCHAR2,
                                 a_csv_data IN CLOB)
    IS
    .
       /*STEPS*/
    .
    END;

But since one of the passing parameters for this PROC is CLOB hence whenever I'm trying to call is PROC using in JOB it throws an error "ORA-06502: PL/SQL: numeric or value error".

As job_action datatype is of VARCHAR2(4000); and hence the moment CLOB datatype is dynamically passed while calling the proc in the Job action it throws an error "ORA-06502: PL/SQL: numeric or value error"

Kindly suggest on this. (can we pass the parameters using bind variables?)


回答1:


The CLOB data has to come from somewhere. Instead of passing it as a parameter to the procedure you should stash it in a table which the job can read. Alternatively could you read the original source as a file, ideally as an external table, or as a BFILE.




回答2:


SYSTIMESTAMP returns a TIMESTAMP WITH TIME ZONE value, so FROM_TZ(SYSTIMESTAMP, 'US/Eastern') is useless and it actually should return an error.

Data type of job_action is VARCHAR2, i.e. up to 32K characters, so CLOB is not possible.

Like APC I recommend a BFILE or an external table for processing.



来源:https://stackoverflow.com/questions/50129452/how-to-create-a-job-when-job-action-need-to-call-a-procedure-having-clob-parame

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!