Skip to Main Content
  • Questions
  • Need to pass an array as an argument value in DBMS_SCHEDULER

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Pete.

Asked: September 20, 2017 - 2:05 pm UTC

Last updated: September 21, 2017 - 2:27 am UTC

Version: 11.2g

Viewed 1000+ times

You Asked

Hi,

So I recently created a stored procedure, in which two of the arguments take a custom type of array, which is like this:

create or replace TYPE QUERY_LST
AS VARRAY(10) OF VARCHAR2(30 CHAR);

The stored procedure works as expected when I directly execute it. I wanted to set up a custom job for running this stored procedure. However, when I try to create the job it throws up an error (PLS-00306) at the exact place where I go to set the argument values of the stored procedure:

DBMS_SCHEDULER.SET_JOB_ANYDATA_VALUE(
job_name => '[JOB]',
argument_position => 5,
argument_value => QUERY_LST('Query1','Query2','Query3'));

I'm not sure what I am doing wrong here. I would appreciate your assistance.

and Connor said...

As the name suggests, you have to pass an argument of type ANYDATA. So a quick conversion and you'll be good to go

SQL> create or replace type my_varray as varray(5) of number;
  2  /

Type created.

SQL>
SQL> drop table t purge;

Table dropped.

SQL>
SQL> create table t ( x int );

Table created.

SQL>
SQL> create or replace
  2  procedure load_t(v my_varray) is
  3  begin
  4    for i in 1 .. v.count loop
  5       insert into t values (v(i));
  6    end loop;
  7    commit;
  8  end;
  9  /

Procedure created.

SQL>
SQL> begin
  2    dbms_scheduler.create_program (
  3      program_name        => 'pgm_load_t',
  4      program_type        => 'stored_procedure',
  5      program_action      => 'load_t',
  6      number_of_arguments => 1,
  7      enabled             => false,
  8      comments            => 'program to run a stored procedure.');
  9
 10    dbms_scheduler.define_program_argument (
 11      program_name      => 'pgm_load_t',
 12      argument_name     => 'v',
 13      argument_position => 1,
 14      argument_type     => 'my_varray');
 15
 16    dbms_scheduler.enable (name => 'pgm_load_t');
 17  END;
 18  /

PL/SQL procedure successfully completed.

SQL> declare
  2    v my_varray := my_varray(1,2,3,4);
  3    a sys.anydata := SYS.ANYDATA.ConvertCollection(v);
  4  begin
  5    dbms_scheduler.create_job (
  6      job_name      => 'job_load_t',
  7      program_name  => 'pgm_load_t',
  8      start_date      => SYSTIMESTAMP,
  9      enabled         => false,
 10      comments        => 'Job to run pgm');
 11
 12  dbms_scheduler.set_job_anydata_value (
 13     job_name           => 'job_load_t',
 14     argument_position  => 1,
 15     argument_value     => a
 16     );
 17
 18   dbms_scheduler.enable ('job_load_t');
 19
 20  end;
 21  /

PL/SQL procedure successfully completed.

SQL>
SQL> select * from t;

         X
----------
         1
         2
         3
         4


Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Pete Jones, September 21, 2017 - 1:54 pm UTC


More to Explore

Scheduler

All of the database utilities including the Scheduler are explained in the Utilities guide.