tonyf
tonyf

Reputation: 35557

Oracle DBMS_SCHEDULER.create_job with OUT parameter call

Env: Oracle 12c

Unsure of the following and require confirmation.

If I call a job_type PLSQL_BLOCK scheduled job that will execute from systdate + 30 secs that has an OUT parameter, I assume after the scheduled job has completed, I will then have access to the OUT param value, i.e. v_status - is this correct based on below code example?

Just unsure when it comes to scheduled jobs.

create or replace package body my_package as

  procedure get_status ( in_curr_id    in      number,
                         o_status      out     varchar2 ) is

  begin
    select status 
    into o_status 
    from my_status_table 
    where curr_id = in_curr_id;
  end get_status;


  procedure process_task is

    v_plsql   varchar2(4000) := null;
    v_status  varchar2(10)   := null;
    v_curr_id number;
  begin
    v_curr_id := 100;
    v_plsql := 'begin get_status (in_curr_id => ' || v_curr_id || ',
                                  o_status   => ' || v_status  || '); end;'
    dbms_scheduler.create_job(job_name   => 'my_scheduled_job', 
                              job_type   => 'PLSQL_BLOCK', 
                              job_action => v_plsql,
                              start_date => sysdate + NUMTODSINTERVAL(30, 'SECOND'), 
                              enabled    => true);
    if v_status = 'OK' then
      -- do required processing
    else
      dbms_output.put_line(v_status);
  end process_task;

end my_package;
/

Upvotes: 1

Views: 1590

Answers (1)

Steven Feuerstein
Steven Feuerstein

Reputation: 1974

As @Tejash points out there is nothing built into DBMS_SCHEDULER that will store values of out arguments in your block. You need to do it yourself.

Change this:

v_plsql := 'begin get_status (in_curr_id => ' || v_curr_id || ',
                              o_status   => ' || v_status  || '); end;'

to this:

v_plsql := 'declare s my_status_table.status%TYPE;
            begin get_status (in_curr_id => ' || v_curr_id || ',
                              o_status   => s); 
                  insert into my_status_table (curr_id, status)
                     values (' || v_curr_id || ', s);
                  commit;
            end;';

Upvotes: 1

Related Questions