DBMS_SCHEDULER.CREATE_PROGRAM (30EA3)

When creating a new program, and selecting Stored Procedure, the drop down of stored procedures only shows actual procedures. It should also show packaged procedures (or at least the packages and then a further drop down for the procedures in that package).
As a workaround, you can directly edit the field and enter package.procedure but then you have to manually create any arguments (using the dbms_scheduler package).
LewisC

Hi
The procedure selection for programs is a bit weak. It will be reviewed for enhancement in a future release.
Thanks
Rob

Similar Messages

  • DBMS_SCHEDULER.CREATE_PROGRAM with Optional input parameters

    I have a procedure that has a number of "optional" parameters.
    procedure get_files(
    file_name_in in varchar2 default 'dummy_file',
    layout_in in number default 1,
    client_in in number default null,
    data_supplier_in in number default 99999
    This procedure can be called with any combination of the input parameters.
    I can set up program(s) using the DBMS_SCHEDULER.CREATE_PROGRAM procedure using a program_type => 'PLSQL_BLOCK' like this:
    begin
    sys.dbms_scheduler.create_program(
    program_name => 'GET_MY_FILES',
    program_action => '
    declare
    begin
    get_files( layout_in => 11111, client_in => 2222 );
    end ;',
    program_type => 'PLSQL_BLOCK',
    number_of_arguments => 0);
    end;
    My question is: Can I set up programs(s) using the DBMS_SCHEDULER.CREATE_PROGRAM procedure using a program_type => 'STORED_PROCEDURE' when I have "optional" parameters?
    It appears that ALL of the program input parameters must be defined and there is no way to indicate that a parameters is "optional".

    Yes you can do it.
    You can defined default values for program parameters, but this values are "constants". So if your default value of parameter is defined by function call you have a problem, because you have to specify this parametr every time.
    procedure my_proc(p_date IN DATE := SYSDATE) AS
    ...There is my example, it using DBADMIN schema create this schema or replace it.
    create or replace procedure dbadmin.sleep(p_interval in number)
    as
    begin
      dbms_lock.sleep(p_interval);
    end;
    --program definition
    begin
        dbms_scheduler.create_program(program_name => 'dbadmin.prg_test1',
                                      program_type => 'STORED_PROCEDURE',
                                      program_action => 'dbadmin.sleep',
                                      number_of_arguments => 1);
        dbms_scheduler.define_program_argument(program_name => 'dbadmin.prg_test1',argument_position => 1,argument_type => 'NUMBER',default_value => 60);
        dbms_scheduler.enable(name => 'dbadmin.prg_test1');                                 
    end;
    --check that program was created
    select * from dba_scheduler_programs
    where owner='DBADMIN';
    select * from dba_scheduler_program_args
    where owner='DBADMIN';
    BEGIN
        dbms_scheduler.create_job(job_name        => 'dbadmin.job_program1',
                                  program_name    => 'dbadmin.prg_test1',
                                  start_date      => to_timestamp_tz('1.1.2010 12:00 Europe/Prague', 'dd.mm.yyyy hh24:mi tzr'),
                                  repeat_interval => 'FREQ=minutely; INTERVAL=2;BYSECOND=0',
                                  auto_drop       => FALSE);
        dbms_scheduler.enable(name => 'dbadmin.job_program1');
    END;
    --job run checks
    SELECT *
    FROM   dba_scheduler_jobs j
    WHERE  j.JOB_NAME = 'JOB_PROGRAM1';
    SELECT *
    FROM   dba_scheduler_job_log jl
    WHERE  jl.JOB_NAME = 'JOB_PROGRAM1';
    SELECT *
    FROM   dba_scheduler_job_run_details jr
    WHERE  jr.JOB_NAME = 'JOB_PROGRAM1';   
    --now set job parametr
    BEGIN
        dbms_scheduler.set_job_argument_value(job_name => 'dbadmin.job_program1', argument_position => 1, argument_value => 30);
    END;
    --clean up
    BEGIN
        dbms_scheduler.drop_job(job_name => 'dbadmin.job_program1', force => TRUE);
        dbms_scheduler.drop_program(program_name => 'dbadmin.prg_test1');
        dbms_scheduler.purge_log;
    END;
    /

  • Guide to External Jobs on 10g with dbms_scheduler e.g. scripts,batch files

    GUIDE TO RUNNING EXTERNAL JOBS ON 10g WITH DBMS_SCHEDULER
    NOTE: Users using 11g should use the new method of specifying a credential which eliminates many of the issues mentioned in this note.
    This guide covers several common questions and problems encountered when using
    dbms_scheduler to run external jobs, either on Windows or on UNIX.
    What operating system (OS) user does the job run as ?
    External jobs which have a credential (available in 11g) run as the user
    specified in the credential. But for jobs without credentials including
    all jobs in 10gR1 and 10gR2 there are several cases.
    - On UNIX systems, in releases including and after 10.2.0.2 there is a file $ORACLE_HOME/rdbms/admin/externaljob.ora . All external jobs not in the SYS schema and with no credential run as the user and group specified in this file. This should be nobody:nobody by default.
    - On UNIX systems, in releases prior to 10.2.0.2 there was no "externaljob.ora" file. In this case all external jobs not in the SYS schema and with no credential run as the owner and group of the $ORACLE_HOME/bin/extjob file which should be setuid and setgid. By default extjob is owned by nobody:nobody except for oracle-xe where it is owned by oracle:oraclegroup and is not setuid/setgid.
    - On Windows, external jobs not in the SYS schema and with no credential run as the user that the OracleJobScheduler Windows service runs as. This service must be started before these jobs can run.
    - In all releases on both Windows and UNIX systems, external jobs in the SYS schema without a credential run as the oracle user.
    What errors are reported in SCHEDULERJOB_RUN_DETAILS views ?
    If a job fails, the first place to look for diagnostic information is the SCHEDULERJOB_RUN_DETAILS set of views. In 10gR2 and up the first 200 characters of the standard error stream is included in the additional_info column.
    In all releases, the error number returned by the job is converted into a
    system error message (e.g. errno.h on UNIX or net helpmsg on Windows) and that
    system error message is recorded in the additional info column. If there is no
    corresponding message the number is displayed.
    In 11g and up the error number returned by the job is additionally recorded in
    the error# column. In earlier releases 27369 would always be recorded in the
    error# column.
    Generic Issues Applicable to UNIX and Windows
    - The job action (script or executable) must return 0 or the job run will be marked as failed.
    - Always use the full pathname to executables and scripts.
    - Do not count on environment variables being set in your job. Make sure that the script or executable that your jobs runs sets all required environment variables including ORACLE_HOME, ORACLE_SID, PATH etc.
    - It is not recommended to pass in a complete command line including arguments as the action. Instead it is recommended to pass in only the path to and name of the executable and to pass in arguments as job argument values.
    - Scripts with special characters in the execution path or script name may give problems.
    - Ensure that the OS user your job runs as has the required privileges/permissions to run your job. See above for how to tell who the job runs as.
    - External job actions cannot contain redirection operators e.g. > < >> | && ||
    - In general try getting a simple external job working first e.g. /bin/echo or ipconfig.exe on Windows. Also try running the job action directly from the commandline as the OS user that the job will run as.
    Windows-specific Issues
    - The OracleJobScheduler Windows service must be started before external jobs will run (except for jobs in the SYS schema and jobs with credentials).
    - The user that the OracleJobScheduler Windows service runs as must have the "Log on as batch job" Windows privilege.
    - A batch file (ending in .bat) cannot be called directly by the Scheduler. Instead cmd.exe must be used and the name of the batch file passed in as an argument. For example
    begin
    dbms_scheduler.create_job('myjob',
       job_action=>'C:\WINDOWS\SYSTEM32\CMD.EXE',
       number_of_arguments=>3,
       job_type=>'executable', enabled=>false);
    dbms_scheduler.set_job_argument_value('myjob',1,'/q');
    dbms_scheduler.set_job_argument_value('myjob',2,'/c');
    dbms_scheduler.set_job_argument_value('myjob',3,'c:\temp\test.bat');
    dbms_scheduler.enable('myjob');
    end;
    /- In 10gR1 external jobs that wrote to standard output or standard error streams would sometimes return errors. Redirect to files or suppress all output and error messages when using 10gR1 to run external jobs.
    UNIX-specific Issues
    - When running scripts, make sure that the executable bit is set.
    - When running scripts directly, make sure that the first line of the script in a valid shebang line - starting with "#!" and containing the interpreter for the script.
    - In release 10.2.0.1, jobs creating a large amount of standard error text may hang when running (this was fixed in the first 10.2.0.2 patchset). If you are seeing this issue, redirect standard error to a file in your job. This issue has been seen when running the expdp utility which may produce large amounts of standard error text.
    - the user that the job runs as (see above section) must have execute access on $ORACLE_HOME/bin and all parent directories. If this is not the case the job may be reported as failed or hang in a running state. For example if your $ORACLE_HOME is /opt/oracle/db then you would have to make sure that
    chmod a+rx /opt
    chmod a+rx /opt/oracle
    chmod a+rx /opt/oracle/db
    chmod a+rx /opt/oracle/db/bin
    - On oracle-xe, the primary group of your oracle user (if it exists) must be dba before you install oracle-xe for external jobs to work. If you have an oracle user from a regular Oracle installation it may have the primary group set to oinstall.
    - On oracle-xe, the extjobo executable is missing so external jobs in the SYS schema will not work properly. This can be fixed by copying the extjob executable to extjobo in the same directory ($ORACLE_HOME/bin).
    - Check that correct permissions are set for external job files - extjob and externaljob.ora (see below)
    Correct permissions for extjob and externaljob.ora on UNIX
    There is some confusion as to what correct permissions are for external job related files.
    In 10gR1 and 10.2.0.1 :
    - rdbms/admin/externaljob.ora should not exist
    - bin/extjob should be setuid and setgid 6550 (r-sr-s---). It should be owned by the user that jobs should run as and by the group that jobs should run as.
    - bin/extjobo should have normal 755 (rwxr-xr-x) permissions and be owned by oracle:oraclegroup
    In 10.2.0.2 and higher
    - rdbms/admin/externaljob.ora file must must be owned by root:oraclegroup and be writable only by the owner i.e. 644 (rw-r--r--) It must contain at least two lines: one specifying the run-user and one specifying the run-group.
    - bin/extjob file must be also owned by root:oraclegroup but must be setuid i.e. 4750 (-rwsr-x---)
    - bin/extjobo should have normal 755 (rwxr-xr-x) permissions and be owned by oracle:oraclegroup
    In 11g and higher
    Same as 10.2.0.2 but additionally bin/jssu should exist with root setuid
    permissions i.e. owned by root:oraclegroup with 4750 (-rwsr-x---)
    Internal Error numbers for UNIX on 10.2.0.2 or 10.1.0.6 or higher
    If you are not using a credential and are using version 10.2.0.2 or higher or 10.1.0.6 or higher you may come across an internal error number. Here are the meanings for the internal error numbers.
    274661 - can't get owner of or permissions of externaljob.ora file
    274662 - not running as root or externaljob.ora file is writable by group or other or externaljob.ora file not owned by root (can't switch user)
    274663 - setting the group or effective group failed
    274664 - setting the user or effective user failed
    274665 - a user or group id was not changed successfully
    274666 - cannot access or open externaljob.ora file
    274667 - invalid run_user specified in externaljob.ora file
    274668 - invalid run_group specified in externaljob.ora file
    274669 - error parsing externaljob.ora file
    274670 - extjobo is running as root user or group

    Hi Ravi,
    Can you help me...
    Hi All,
    I planned to create a job to do rman backup daily at 04:00 AM.
    1. I created a program as follows
    BEGIN
    DBMS_SCHEDULER.CREATE_PROGRAM(
    program_name => 'rman_backup_prg',
    program_action => '/u02/rmanback/rman.sh',
    program_type => 'EXECUTABLE',
    comments => 'RMAN BACKUP');
    END;
    my rman script is
    #!/usr/bin/ksh
    export ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
    export PATH=$PATH:/u01/app/oracle/product/10.2.0/db_1/bin
    /u01/app/oracle/product/10.2.0/db_1/bin/exp rman/cat@catdb file=/u02/rmanback/rm
    an_220108.dmp log=/u02/rmanback/rman_220108.log owner=rman statistics=none comp
    ress=n buffer=400000
    compress *.dmp
    exit
    2. I created a schedule as follows
    BEGIN
    DBMS_SCHEDULER.CREATE_SCHEDULE(
    schedule_name => 'rman_backup_schedule',
    start_date => SYSTIMESTAMP,
    end_date => '31-DEC-16 05.00.00 AM',
    repeat_interval => 'FREQ=DAILY; BYHOUR=4',
    comments => 'Every day at 4 am');
    END;
    3. I created ajob as follows.
    BEGIN
    DBMS_SCHEDULER.CREATE_JOB (
    job_name => 'rman_backup_job',
    program_name => 'rman_backup_prg',
    schedule_name => 'rman_backup_schedule',
    enabled=> true,
    auto_drop=> false
    END;
    While I am running the job I am getting the following error anybody help me.
    ORA-27369: job of type EXECUTABLE failed with exit code: Not owner
    ORA-06512: at "SYS.DBMS_ISCHED", line 150
    ORA-06512: at "SYS.DBMS_SCHEDULER", line 441
    ORA-06512: at line 2
    If I removed "compress *.dmp" line in rman script it is working fine.
    /* additional Info from dba_scheduler_job_run_details as follows */
    ORA-27369: job of type EXECUTABLE failed with exit code: Not owner
    STANDARD_ERROR="
    Export: Release 10.2.0.3.0 - Production on Tue Jan 22 14:30:08 2008
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    Connected to: Oracle Database 10g Release 10.2.0.3.0 - Production
    Export"
    Regards,
    Kiran

  • Stored Proc running twice using DBMS_Scheduler

    Hello all,
    I have a vb front end that calls a main stored proc which submits scheduler jobs to execute several stored procs asynchronously. Everything is working, except the part that the several stored procs are running twice. In the troubleshooting, I have eliminated the front end from being the culprit and the stored procs themselves. Essentially, when I call the stored proc using dbms_scheduler.create_job, it runs twice, even manually. I am about at wits end trying to figure out why: Using Oracle 11gR2
    I started off setting up the programs
    begin
    --create program
    dbms_scheduler.create_program
    ( program_name => 'prog_name'
    ,program_type => 'STORED_PROCEDURE'
    ,program_action => 'usp_sub_proc_1'
    ,number_of_arguments => 8
    ,enabled => FALSE
    dbms_scheduler.DEFINE_PROGRAM_ARGUMENT
    ( program_name=> 'prog_name'
    ,argument_position=>1
    ,argument_name => 'name'
    ,argument_type=>'VARCHAR2'
    /*the remaining 7 arguments are in code but not display for space reasons*/
    dbms_scheduler.enable('prog_name');
    end;Then the main stored proc executes this code:
    declare v_job_name varchar2(100);
        v_1 varchar(50) := 'All';
        v_2 varchar(50) := 'All';
        v_3 varchar(50) := 'All';
        v_4 varchar(50) := 'All';
        v_5 varchar(50) := 'TEST';
        i_6 integer := 1;
        v_7 varchar(50) := 'TEST_NE';
        ts_8 timestamp := current_timestamp;
    begin
        v_job_name := 'uj_dmo_1';
    dbms_scheduler.create_job (v_job_name
                                            ,program_name => 'prog_name'
                                            ,job_class => 'UCLASS_1'
                                            ,auto_drop => TRUE
    --set parameters
    dbms_scheduler.set_job_argument_value(v_job_name,1, v_1);
    dbms_scheduler.set_job_argument_value(v_job_name,2, v_2);
    dbms_scheduler.set_job_argument_value(v_job_name,3, v_3);
    dbms_scheduler.set_job_argument_value(v_job_name,4, v_4);
    dbms_scheduler.set_job_argument_value(v_job_name,5, v_5);
    dbms_scheduler.set_job_argument_value(v_job_name,6, to_char(i_6));
    dbms_scheduler.set_job_argument_value(v_job_name,7, v_7);
    dbms_scheduler.set_job_argument_value(v_job_name ,8, to_char(ts_8));
    --enable job
    dbms_scheduler.enable(v_job_name);
    --execute job
    dbms_scheduler.run_job(job_name => v_job_name , use_current_session => FALSE);
    end;
    ...And this is where I get the double execution of the job, but I am just not seeing it in my syntax, dba_scheduler_jobs, logging, etc. Any help is greatly appreciated, thanks!!

    Well apparently I will not win any Captain Obvious awards;
    With 34MCA2K2's response with "what doesn't work" for some reason turned the light on. After some more testing here is what I found.
    This code works as expected :
    Exhibit A
    begin
    dbms_scheduler.create_job (job_name =>'TESTER'
                                   ,job_type => 'PLSQL_BLOCK'
                                   ,job_action => 'declare test1 integer := 1; begin test1 := test1 + 5; end;'
                                   ,auto_drop => True
       /*dbms_scheduler.enable('TESTER');   */
       dbms_scheduler.run_job(job_name => 'TESTER', use_current_session =>FALSE);   
    end;As does this:
    Exhibit B
    begin
    dbms_scheduler.create_job (job_name =>'TESTER'
                                   ,job_type => 'PLSQL_BLOCK'
                                   ,job_action => 'declare test1 integer := 1; begin test1 := test1 + 5; end;'
                                   ,auto_drop => True
       dbms_scheduler.enable('TESTER');  
      /*dbms_scheduler.run_job(job_name => 'TESTER', use_current_session =>FALSE);    */
    end;Exhibit A will create the job and is visible in the schedulerjobs view, and the RUN_JOB will execute it even when not enabled, but the pl/sql will not drop the job.
    Exhibit B will create the job and once enabled, executes the job and then drops from schedulerjobs view.
    Therefore, my desired results for running the jobs once asynchronously and dropping immediately is....
    begin
        v_job_name := 'uj_dmo_1';
    dbms_scheduler.create_job (v_job_name
                                            ,program_name => 'prog_name'
                                            ,job_class => 'UCLASS_1'
                                            ,auto_drop => TRUE
    --set parameters
    dbms_scheduler.set_job_argument_value(v_job_name,1, v_1);
    dbms_scheduler.set_job_argument_value(v_job_name,2, v_2);
    dbms_scheduler.set_job_argument_value(v_job_name,3, v_3);
    dbms_scheduler.set_job_argument_value(v_job_name,4, v_4);
    dbms_scheduler.set_job_argument_value(v_job_name,5, v_5);
    dbms_scheduler.set_job_argument_value(v_job_name,6, to_char(i_6));
    dbms_scheduler.set_job_argument_value(v_job_name,7, v_7);
    dbms_scheduler.set_job_argument_value(v_job_name ,8, to_char(ts_8));
    /*enable job*/
    dbms_scheduler.enable(v_job_name);
    /*execute job (Do not execute the code below, it will lead to multiple executions)
    dbms_scheduler.run_job(job_name => v_job_name , use_current_session => FALSE); */
    end;

  • Error while defining chain_step using dbms_scheduler.define_chain_step

    Hello,
    I am trying to create a chain_job using dbms_scheduler in <Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit>
    BEGIN
    dbms_scheduler.create_chain (
    chain_name => 'test_chain',
    rule_set_name => NULL,
    evaluation_interval => NULL,
    comments => 'Test chain.');
    END;
    -- Chain Created Successfully
    begin
    dbms_scheduler.create_program (
    program_name => 'test_program',
    program_type => 'PLSQL_BLOCK',
    program_action => 'BEGIN null; END;',
    enabled => TRUE,
    comments => 'Test program.');
    end;
    -- Program Created Successfully
    begin
    dbms_scheduler.define_chain_step (
    chain_name => 'test_chain',
    step_name => 'step_maximum_length_allowed',
    program_name => 'test_program');
    end;
    Error at line 1
    ORA-27465: invalid value STEP_MAXIMUM_LENGTH_ALLOWED for attribute step_name
    ORA-06512: at "SYS.DBMS_ISCHED", line 3912
    ORA-06512: at "SYS.DBMS_ISCHED", line 1452
    ORA-06512: at "SYS.DBMS_SCHEDULER", line 1364
    ORA-06512: at line 2
    The step_name length I used above<'step_maximum_length_allowed'> is 27 characters.
    If I use a step_name of length <= 24 characters, the define_chain_step works.
    Question:
    Does this error have to do with the maximum length allowed for step_name. If so, then the error raised should have reflected that.
    Appreciate any help.
    Thanks
    Kumar
    Edited by: 977325 on Jan 10, 2013 12:01 PM
    Edited by: 977325 on Jan 10, 2013 12:01 PM
    Edited by: 977325 on Jan 10, 2013 12:03 PM

    Thanks a lot damorgan for your reply :)
    I have gone through the link you provided. I couldn't find any limits on step naming though.
    Here is the question again with proper with proper formatting.
    I am trying to create a chain_job using dbms_scheduler in <Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit>
    BEGIN
       DBMS_SCHEDULER.create_chain (chain_name            => 'test_chain',
                                    rule_set_name         => NULL,
                                    evaluation_interval   => NULL,
                                    comments              => 'Test chain.');
    END;
    -- Chain Created Successfully
    BEGIN
       DBMS_SCHEDULER.create_program (program_name     => 'test_program',
                                      program_type     => 'PLSQL_BLOCK',
                                      program_action   => 'BEGIN null; END;',
                                      enabled          => TRUE,
                                      comments         => 'Test program.');
    END;
    -- Program Created Successfully
    <code>
    BEGIN
       DBMS_SCHEDULER.define_chain_step (
          chain_name     => 'test_chain',
          step_name      => 'step_maximum_length_allowed',
          program_name   => 'test_program');
    END;
    Error at line 1
    ORA-27465: invalid value STEP_MAXIMUM_LENGTH_ALLOWED for attribute step_name
    ORA-06512: at "SYS.DBMS_ISCHED", line 3912
    ORA-06512: at "SYS.DBMS_ISCHED", line 1452
    ORA-06512: at "SYS.DBMS_SCHEDULER", line 1364
    ORA-06512: at line 2Question:
    The step_name length I used above is 27 characters.
    If I use a step_name of length <= 24 characters, the define_chain_step works.
    Does this error have to do with the maximum length allowed for step_name. If so, then the error raised should have reflected that.

  • Dbms_scheduler.file_watch will only pull in files with t/s = last run...

    Hello,
    I may be missing something easy, but instead of spinning my wheels I'll ask.
    I am new to using the file_watcher in the dbms_scheduler so I followed the directions posted in this link:
    http://awads.net/wp/2011/03/29/did-you-know-about-file-watchers/
    Now this works, I can process the file.
    But the file_watcher WILL ONLY Pull files that are modified/created AFTER the last run.
    Since I am NOT running this in parallel, that means any file not picked up in the initial run will simply sit out there aging.
    Am I missing something? I understand that it may be desired behavior to only pick up new files, but our process moves the files out of the directory once they are found. It seems odd that if you do not run it in parallel the file will be ignored forever more.
    Am I missing a param?
    --Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    BEGIN
          DBMS_SCHEDULER.create_program (
             program_name          => 'FILE_INGEST',
             program_type          => 'STORED_PROCEDURE',
             program_action        => 'Package.Procedure',
             number_of_arguments   => 1,
             enabled               => FALSE);
          DBMS_SCHEDULER.define_metadata_argument (
             program_name         => 'FILE_INGEST',
             metadata_attribute   => 'event_message',
             argument_position    => 1);
          DBMS_SCHEDULER.enable ('FILE_INGEST');
          DBMS_SCHEDULER.create_file_watcher (
             file_watcher_name   => 'watcher_fw',
             directory_path      => '/mydiriwanttowatch',
             file_name           => '*',
             credential_name     => 'sys.cred' ,
             destination         => NULL,
             enabled             => FALSE );
          DBMS_SCHEDULER.create_job (
             job_name          => 'FILE_INGEST_WATCHER',
             program_name      => 'FILE_INGEST',
             queue_spec        => 'watcher_fw',
             auto_drop         => FALSE,
             enabled           => FALSE);
        DBMS_SCHEDULER.enable ('watcher_fw,FILE_INGEST_WATCHER');
    END;
    /

    okay,
    Lets say the time of the last run is
    05/12/2011 @18:00pm
    I place three files into the directory
    File1 05/12/2011 18:01
    File2 05/12/2011 18:02
    File3 05/12/2011 18:03
    At the 18:10 run, file1 is picked up and processed
    File2 and File3 never get processed or sent to the stored procedure to run (even on the 18:20, 18:30 etc file_watcher runs). however, if I go into file2 and make a change (at 18:35) the 18:40 run will pick it up...
    but without manual intervention File3 will never get sent to the stored procedure.
    I would expect, at the minimum, that on the first file_watcher job that ran file1 would be picked up, then file2 and file3 and the next subsequent runs (without manipulation).
    what I mean about not running in Parallel:
    DBMS_SCHEDULER.set_attribute('FILE_INGEST_WATCHER','parallel_instances',FALSE);Edited by: Harrison on May 12, 2011 3:11 PM

  • DBMS_SCHEDULER.run_chain() only works when connected to DB as sys

    Database Version: 10.2.0.4.0
    Hello,
    I have a problem with DBMS_SCHEDULER.run_chain where the Chain to be run references an external Program.
    The Chain runs correctly when run via SQLPLUS when you are connected to the database as SYS but fails to run when you are connected to the Database as the User who owns the Chain.
    The complete steps to recreate the problem are below. Any thoughts or suggestions gratefully received.
    Thanks,
    Andy
    STEP 1: Login with sys as sysdba and create a new user
    CREATE USER chaintest IDENTIFIED BY password PROFILE DEFAULT ACCOUNT UNLOCK;
    GRANT MGMT_USER TO chaintest;
    GRANT CONNECT TO chaintest;
    GRANT IMP_FULL_DATABASE TO chaintest;
    GRANT SCHEDULER_ADMIN TO chaintest;
    GRANT MANAGE SCHEDULER TO chaintest;
    GRANT EXECUTE ANY CLASS TO chaintest;
    GRANT CREATE ANY DIRECTORY TO chaintest;
    GRANT CREATE ANY JOB TO chaintest;
    GRANT CREATE TABLE TO chaintest;
    GRANT EXECUTE ANY PROGRAM TO chaintest;
    GRANT CREATE JOB TO chaintest;
    GRANT CREATE EXTERNAL JOB TO chaintest;
    STEP 2: Create a very simple batch file
    Create a folder called c:\chaintest and create a text file in there whose entire contents
    is "notepad.exe" followed by a carriage return. The idea is that if this batch file is
    called a notepad Window will be opened so we can clearly see if the batch file has run.
    STEP 3: Create a DBMS_SCHEDULER Program
    BEGIN
    DBMS_SCHEDULER.CREATE_PROGRAM (
    program_name => 'CHAINTEST.CHAINTEST_PROGRAM',
    program_type => 'EXECUTABLE',
    program_action => 'C:\WINDOWS\SYSTEM32\CMD.EXE /q /c c:\chaintest\chaintest.bat',
    number_of_arguments => 3,
    enabled => false);
    DBMS_SCHEDULER.define_program_argument(
    program_name =>'CHAINTEST.CHAINTEST_PROGRAM',
    argument_position => 1,
    argument_type => 'VARCHAR2',
    default_value => '/q');
    DBMS_SCHEDULER.define_program_argument(
    program_name =>'CHAINTEST.CHAINTEST_PROGRAM',
    argument_position => 2,
    argument_type => 'VARCHAR2',
    default_value => '/c');
    DBMS_SCHEDULER.define_program_argument(
    program_name =>'CHAINTEST.CHAINTEST_PROGRAM',
    argument_position => 3,
    argument_type => 'VARCHAR2',
    default_value => 'c:\chaintest\chaintest.bat');
    DBMS_SCHEDULER.enable('CHAINTEST.CHAINTEST_PROGRAM');
    END;
    STEP 4: Create a chain
    BEGIN
    DBMS_SCHEDULER.CREATE_CHAIN (chain_name => 'CHAINTEST.CHAINTEST_CHAIN');
    END;
    STEP 5: Create the only Chain Step
    BEGIN
    DBMS_SCHEDULER.DEFINE_CHAIN_STEP(chain_name=>'CHAINTEST.CHAINTEST_CHAIN'
    , step_name=>'STEPA'
    , program_name=>'CHAINTEST.CHAINTEST_PROGRAM');
    END;
    STEP 6: Create Chain Rules
    BEGIN
    DBMS_SCHEDULER.DEFINE_CHAIN_RULE(
    chain_name=>'CHAINTEST.CHAINTEST_CHAIN'
    , condition=>'TRUE'
    , action=>'START STEPA');
    DBMS_SCHEDULER.DEFINE_CHAIN_RULE(
    chain_name=>'CHAINTEST.CHAINTEST_CHAIN'
    , condition=>'STEPA COMPLETED'
    , action=>'END');
    END;
    STEP 7: Enable the Chain
    BEGIN
    DBMS_SCHEDULER.enable('CHAINTEST.CHAINTEST_CHAIN');
    END;
    STEP 8: Run the Chain whilst still connected as sys and observe that a Notepad window opens
    confirming that the Batch file ran successfully.
    BEGIN
    DBMS_SCHEDULER.run_chain(
    chain_name=>'CHAINTEST.CHAINTEST_CHAIN'
    , start_steps=>NULL);
    END;
    STEP 9: Connect to the database as the CHAINTEST user and run the same command as in STEP 8 above.
    Observe that even though you receive the message "PL/SQL procedure successfully completed." and do
    not see any error messages that no Notepad Window is opened indicating that the Batch file was NOT run.
    BEGIN
    DBMS_SCHEDULER.run_chain(
    chain_name=>'CHAINTEST.CHAINTEST_CHAIN'
    , start_steps=>NULL);
    END;

    >
    The Chain runs correctly when run via SQLPLUS when you are connected to the database as SYS but fails to run when you are connected to the Database as the User who owns the Chain.
    >
    Not true based on what you posted. The chain DOES RUN connected as SYS and when connected as the User who owns the chain.
    You posted steps that show that SYS is the user that owns the program and thus the chain.
    >
    STEP 1: Login with sys as sysdba and create a new user
    STEP 8: Run the Chain whilst still connected as sys and observe that a Notepad window opens
    confirming that the Batch file ran successfully.
    >
    I don't see where you made any EXECUTE grant to user 'chaintest' that would allow that user to execute the program.
    See the Usage Notes in the CREATE PROGRAM section of DBMS_SCHEDULER in the Database PL/SQL Packages and Types Reference
    http://docs.oracle.com/cd/B28359_01/appdev.111/b28419/d_sched.htm#CIHEHDHA
    >
    For other users to use your programs, they must have EXECUTE privileges, therefore once a program has been created, you have to grant EXECUTE privileges on it.
    >
    Grant the EXECUTE privilege to user 'chaintest' and try it.

  • DBMS_SCHEDULER wait for job/program to finish

    Hello All,
    I've run into a little limitation on my understanding of DBMS_SCHEDULER.
    I have an executable script which does a network scan. My goal is to lauch this from an application, and wait (could be 5 minutes or 2 hours) for the scan to finish before I return the results.
    Where I'm a little confused, is the flow of the entire process works when I want to wait for the program to complete:
    1 - Define a program?
    2 - Apply arguments?
    3 - Apply credentials
    4 - Define a chain?
    Literally, I'm not sure how to tackle this task. I simply wish to launch to job and wait for it to finish before I go retreive the file from the server. This is what I have so far, just bits and pieces.
    Mayeb I simply missed somethign in the docs, and I'm overcomplicate things.
    Thanks in advance to the community for you assistance.
    Jan S.
    BEGIN
      dbms_scheduler.create_program(
        program_name   => 'network_scan',
        program_type   => 'executable',
        number_of_arguments => 5,
        program_action => 'scan_network.py',
        enabled        =>  FALSE);
      dbms_scheduler.define_program_argument('network_scan',1,'x01=1');
      dbms_scheduler.define_program_argument('network_scan',2,'x02=192.168.1.1');
      dbms_scheduler.define_program_argument('network_scan',3,'x03=24');
      dbms_scheduler.define_program_argument('network_scan',4,'x04=D');
      dbms_scheduler.define_program_argument('network_scan',5,'x05=1521-1523,7777'); 
      vJobName := dbms_scheduler.generate_job_name('NET_SCAN_');
      dbms_scheduler.create_job(job_name => vJobName,
                                  job_type => 'EXECUTABLE',
                                  job_action => '/usr/bin/scan_nework.sh',
                                  number_of_arguments => 5,
                                  enabled => FALSE,
                                  auto_drop => FALSE,
                                  comments => 'Network');
    dbms_scheduler.set_attribute(vJobName,'credential_name', 'SUCREDENTIALS');
      dbms_scheduler.run_job(vJobName,FALSE);
      dbms_scheduler.create_chain (
       chain_name            =>  'net_scan_chain',
       rule_set_name         =>  NULL,
       evaluation_interval   =>  NULL,
       comments              =>  NULL);
      dbms_scheduler.define_chain_step('net_scan_chain', 'step1', 'network_scan');
      SELECT additional_info, external_log_id
      INTO   l_additional_info, l_external_log_id
      FROM   (SELECT log_id,
                     additional_info,
                     REGEXP_SUBSTR(additional_info,'job[_0-9]*') AS external_log_id
              FROM   dba_scheduler_job_run_details
              WHERE  job_name = vJobName
              ORDER BY log_id DESC)
      WHERE  ROWNUM = 1;
      DBMS_OUTPUT.put_line('ADDITIONAL_INFO: ' || l_additional_info);
      DBMS_OUTPUT.put_line('EXTERNAL_LOG_ID: ' || l_external_log_id); 
      -- Wait at least 3 second because its distributed
      dbms_lock.sleep(3);
      SELECT job_name, status, error#, additional_info
      FROM dba_scheduler_job_run_details
      WHERE job_name= vJobName;
      dbms_lob.createtemporary(l_clob, FALSE);
      dbms_scheduler.get_file(
        source_file     => l_external_log_id ||'_stdout',
        credential_name => 'ORACLECREDENTIALS',
        file_contents   => l_clob,
        source_host     => NULL);
      DBMS_OUTPUT.put_line('stdout:');
      DBMS_OUTPUT.put_line(l_clob);
    k Scan');

    See Tom's last reply in this AskTom thread. It shows how to use the DBMS_ALERT package to signal you.
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:5320945700346034393

  • Dbms_scheduler - dbms_aq - dbms_aqadm - event driven job runs only once/sec

    hi, i tried here to process events with 2 jobs... surprisingly i had to call dbms_lock.sleep(1) to be able to enqueue events
    at inserts in a row ... even more surprisingly the enqueuing doesn't function if the processing (prc_evsched) lasts some seconds...
    how must the code be changed to be able to enqueue all events after the inserts without any sleep()?
    and how must the code be changed to be able to enqueue all events with a proc (prc_evsched) running longer?
    thanx in advance for your help!
    --evsched
    h4.
    --to remove all test-objects
    h4.
    --test table
    h4.
    --define the object type to act as the payload for the queue
    h4.
    --creating the event queue
    h4.
    --creating the proc for the prog/job
    h4.
    --creating the proc for the prog/job
    h4.
    --creating the program
    h4.
    --creating the first job (for parallel execution)
    h4.
    --creating the second job (for parallel execution)
    h4.
    --test block
    h4.
    --test scenarios/results
    h4.
    --to remove all test-objects
    DECLARE
    exc_ora_27475 EXCEPTION; --ora-27475: <job_name> muss job sein
    PRAGMA EXCEPTION_INIT (exc_ora_27475, -27475);
    exc_ora_27476 EXCEPTION; --ora-27476: <program_name> ist nicht vorhanden
    PRAGMA EXCEPTION_INIT (exc_ora_27476, -27476);
    exc_ora_24010 EXCEPTION; --ORA-24010: QUEUE SYSGIS.EVENT_QUEUE ist nicht vorhanden
    PRAGMA EXCEPTION_INIT (exc_ora_24010, -24010);
    exc_ora_24002 EXCEPTION; --ORA-24002: QUEUE_TABLE SYSGIS.EVENT_QUEUE_TAB ist nicht vorhanden
    PRAGMA EXCEPTION_INIT (exc_ora_24002, -24002);
    exc_ora_4043 EXCEPTION; --ORA-04043: Objekt T_EVENT_QUEUE_PAYLOAD ist nicht vorhanden
    PRAGMA EXCEPTION_INIT (exc_ora_4043, -4043);
    exc_ora_942 EXCEPTION; --ORA-00942: Tabelle oder View nicht vorhanden
    PRAGMA EXCEPTION_INIT (exc_ora_942, -942);
    exc_ora_2289 EXCEPTION; --ORA-02289: Sequence ist nicht vorhanden.
    PRAGMA EXCEPTION_INIT (exc_ora_2289, -2289);
    v_fpos PLS_INTEGER := 1;
    BEGIN
    v_fpos := 10;
    BEGIN
    --remove job
    SYS.DBMS_SCHEDULER.DROP_JOB(job_name=> 'job_evsched', FORCE=>TRUE);
    EXCEPTION WHEN exc_ora_27475 THEN NULL;
    END;
    v_fpos := 12;
    BEGIN
    --remove job
    SYS.DBMS_SCHEDULER.DROP_JOB(job_name=> 'job_evsched_2', FORCE=>TRUE);
    EXCEPTION WHEN exc_ora_27475 THEN NULL;
    END;
    v_fpos := 20;
    BEGIN
    --remove program
    SYS.DBMS_SCHEDULER.DROP_PROGRAM(program_name=>'prg_evsched',FORCE=>TRUE);
    EXCEPTION WHEN exc_ora_27476 THEN NULL;
    END;
    v_fpos := 30;
    BEGIN
    -- stop the event queue.
    DBMS_AQADM.stop_queue (queue_name => 'evsched_event_queue');
    EXCEPTION WHEN exc_ora_24010 THEN NULL;
    END;
    v_fpos := 40;
    BEGIN
    -- drop the event queue.
    DBMS_AQADM.drop_queue (queue_name => 'evsched_event_queue');
    EXCEPTION WHEN exc_ora_24010 THEN NULL;
    END;
    v_fpos := 50;
    BEGIN
    -- Remove the queue table.
    DBMS_AQADM.drop_queue_table(queue_table => 'tab_evsched_event_queue');
    EXCEPTION WHEN exc_ora_24002 THEN NULL;
    END;
    v_fpos := 60;
    BEGIN
    -- remove type
    EXECUTE IMMEDIATE 'DROP TYPE typ_evsched_payload';
    EXCEPTION WHEN exc_ora_4043 THEN NULL;
    END;
    v_fpos := 70;
    BEGIN
    -- remove table
    EXECUTE IMMEDIATE 'DROP TABLE tab_evsched';
    EXCEPTION WHEN exc_ora_942 THEN NULL;
    END;
    v_fpos := 80;
    BEGIN
    -- remove sequence
    EXECUTE IMMEDIATE 'DROP SEQUENCE seq_evsched';
    EXCEPTION WHEN exc_ora_2289 THEN NULL;
    END;
    EXCEPTION
    WHEN OTHERS THEN
    dbms_output.put_line('v_fpos='||v_fpos);
    END;
    h4.
    --test table
    CREATE TABLE tab_evsched
    ( id NUMBER
    , sys_date DATE
    , status VARCHAR2(1)
    , processed VARCHAR2(1) DEFAULT 'N'
    , processed_by varchar2(128)
    GRANT DELETE, INSERT, SELECT, UPDATE ON tab_evsched TO PUBLIC
    CREATE SEQUENCE seq_evsched
    h4.
    --define the object type to act as the payload for the queue
    CREATE OR REPLACE TYPE typ_evsched_payload AS OBJECT
    ( event_name VARCHAR2(30)
    , tab_evsched_id NUMBER
    , daterf DATE
    h4.
    --creating the event queue
    BEGIN
    -- Create a queue table to hold the event queue.
    DBMS_AQADM.create_queue_table
    ( queue_table => 'tab_evsched_event_queue'
    , queue_payload_type => 'typ_evsched_payload'
    , multiple_consumers => TRUE
    , COMMENT => 'Queue Table For Event Messages'
    -- Create the event queue.
    DBMS_AQADM.create_queue
    ( queue_name => 'evsched_event_queue'
    , queue_table => 'tab_evsched_event_queue'
    , queue_type => DBMS_AQADM.NORMAL_QUEUE
    , max_retries => 0
    , retry_delay => 0
    , dependency_tracking => FALSE
    , comment => 'Test Object Type Queue'
    , auto_commit => FALSE
    -- Start the event queue.
    DBMS_AQADM.start_queue
    ( queue_name => 'evsched_event_queue'
    END;
    h4.
    --creating the proc for the prog/job
    CREATE OR REPLACE PROCEDURE prc_evsched
    ( p_message IN typ_evsched_payload
    , p_job_name IN VARCHAR2
    IS
    BEGIN
    UPDATE tab_evsched
    SET processed = 'J'
    , processed_by = p_job_name
    , sys_date = p_message.daterf
    WHERE 1=1
    AND id = p_message.tab_evsched_id
    dbms_lock.sleep(5); --#sleep-1#
    COMMIT;
    END prc_evsched;
    h4.
    --creating the program
    DECLARE
    exc_ora_27476 EXCEPTION; --ora-27476: <program_name> ist nicht vorhanden
    PRAGMA EXCEPTION_INIT (exc_ora_27476, -27476);
    BEGIN
    BEGIN
    SYS.DBMS_SCHEDULER.DROP_PROGRAM(program_name=>'prg_evsched',FORCE=>TRUE);
    EXCEPTION
    WHEN exc_ora_27476 THEN
    NULL;
    END;
    SYS.DBMS_SCHEDULER.CREATE_PROGRAM
    ( program_name => 'prg_evsched'
    , program_type => 'STORED_PROCEDURE'
    , program_action => '"SYSGIS"."PRC_EVSCHED"'
    , number_of_arguments => 2
    , enabled => FALSE
    , comments => 'Program-Komponent für den Test von DBMS_SCHEDULER'
    --event message as the first param to prc_evsched 
    DBMS_SCHEDULER.DEFINE_METADATA_ARGUMENT
    ( program_name => 'prg_evsched'
    , argument_position => 1
    , metadata_attribute => 'EVENT_MESSAGE'
    --name of the job as the second param to prc_evsched 
    SYS.DBMS_SCHEDULER.define_program_argument
    ( program_name => 'prg_evsched'
    , argument_name => 'p_job_name'
    , argument_position => 2
    , argument_type => 'VARCHAR2'
    , default_value => 'dummy'
    --enable program   
    SYS.DBMS_SCHEDULER.ENABLE(NAME=>'prg_evsched');
    END;
    h4.
    --creating the first job (for parallel execution)
    DECLARE
    exc_ora_27475 EXCEPTION; --ora-27475: <job_name> muss job sein
    PRAGMA EXCEPTION_INIT (exc_ora_27475, -27475);
    BEGIN
    BEGIN
    --remove job
    SYS.DBMS_SCHEDULER.DROP_JOB(job_name=> 'job_evsched', FORCE=>TRUE);
    EXCEPTION WHEN exc_ora_27475 THEN NULL;
    END;
    DBMS_SCHEDULER.create_job
    ( job_name => 'job_evsched'
    , program_name => 'prg_evsched'
    , start_date => SYSTIMESTAMP
    , event_condition => 'tab.user_data.event_name = ''MYEVENT'''
    , queue_spec => 'evsched_event_queue'
    , auto_drop => FALSE
    , enabled => FALSE
    SYS.DBMS_SCHEDULER.SET_JOB_ARGUMENT_VALUE
    ( job_name => 'job_evsched'
    , argument_name => 'p_job_name'
    , argument_value => 'job_evsched'
    SYS.DBMS_SCHEDULER.ENABLE(NAME=>'job_evsched');
    END;
    h4.
    --creating the second job (for parallel execution)
    DECLARE
    exc_ora_27475 EXCEPTION; --ora-27475: <job_name> muss job sein
    PRAGMA EXCEPTION_INIT (exc_ora_27475, -27475);
    BEGIN
    BEGIN
    --remove job
    SYS.DBMS_SCHEDULER.DROP_JOB(job_name=> 'job_evsched_2', FORCE=>TRUE);
    EXCEPTION WHEN exc_ora_27475 THEN NULL;
    END;
    DBMS_SCHEDULER.create_job
    ( job_name => 'job_evsched_2'
    , program_name => 'prg_evsched'
    , start_date => SYSTIMESTAMP
    , event_condition => 'tab.user_data.event_name = ''MYEVENT'''
    , queue_spec => 'evsched_event_queue'
    , auto_drop => FALSE
    , enabled => FALSE
    SYS.DBMS_SCHEDULER.SET_JOB_ARGUMENT_VALUE
    ( job_name => 'job_evsched_2'
    , argument_name => 'p_job_name'
    , argument_value => 'job_evsched_2'
    SYS.DBMS_SCHEDULER.ENABLE(NAME=>'job_evsched_2');
    END;
    h4.
    --test block
    DECLARE
    PROCEDURE pr_ins_tab_evsched
    ( p_id IN NUMBER
    , p_status IN VARCHAR2
    IS
    BEGIN
    INSERT INTO tab_evsched(id,status) VALUES (p_id, p_status);
    COMMIT;
    --enqueue the MYEVENT-event
    IF p_status = 'M' THEN
    --enqueue works in 1sekunden-taktung.... !?
    dbms_lock.sleep(1); --#sleep-2#
    DECLARE
    v_enqueue_options DBMS_AQ.enqueue_options_t;
    v_message_properties DBMS_AQ.message_properties_t;
    v_message_handle RAW(16);
    v_queue_msg typ_evsched_payload;
    BEGIN
    v_queue_msg := typ_evsched_payload
    ( event_name => 'MYEVENT'
    , tab_evsched_id => p_id
    , daterf => SYSDATE
    v_enqueue_options.VISIBILITY := DBMS_AQ.ON_COMMIT;
    v_enqueue_options.delivery_mode := DBMS_AQ.PERSISTENT;
    v_message_properties.PRIORITY := 1;
    v_message_properties.DELAY := DBMS_AQ.NO_DELAY;
    v_message_properties.EXPIRATION := DBMS_AQ.NEVER;
    v_message_properties.CORRELATION := 'TEST MESSAGE';
    DBMS_AQ.enqueue
    ( queue_name => 'evsched_event_queue'
    , enqueue_options => v_enqueue_options
    , message_properties => v_message_properties
    , payload => v_queue_msg
    , msgid => v_message_handle
    END;
    END IF;
    COMMIT;
    END pr_ins_tab_evsched;
    BEGIN
    DELETE tab_evsched;
    pr_ins_tab_evsched (seq_evsched.NEXTVAL,'M');
    pr_ins_tab_evsched (seq_evsched.NEXTVAL,'M');
    pr_ins_tab_evsched (seq_evsched.NEXTVAL,'M');
    pr_ins_tab_evsched (seq_evsched.NEXTVAL,'M');
    pr_ins_tab_evsched (seq_evsched.NEXTVAL,'M');
    pr_ins_tab_evsched (seq_evsched.NEXTVAL,'M');
    pr_ins_tab_evsched (seq_evsched.NEXTVAL,'M');
    pr_ins_tab_evsched (seq_evsched.NEXTVAL,'M');
    END;
    SELECT * FROM tab_evsched ORDER BY id;
    SELECT * FROM sysgis.tab_evsched_event_queue;
    h4.
    --test scenarios/resultsh
    h5.
    --test results #sleep-1#=5, #sleep-2#=0
    --job (job_evsched) runs only once, only the first event is enqued/processed
    ID SYS_DATE STATUS PROCESSED PROCESSED_BY
    9 22.03.2012 17:00:41 M J job_evsched
    10 (Null) M N (Null)
    11 (Null) M N (Null)
    12 (Null) M N (Null)
    13 (Null) M N (Null)
    14 (Null) M N (Null)
    15 (Null) M N (Null)
    16 (Null) M N (Null)
    h5.
    --test results #sleep-1#=0, #sleep-2#=1
    --jobs (job_evsched/job_evsched2) run alternately, every events are enqued/processed
    ID SYS_DATE STATUS PROCESSED PROCESSED_BY
    25 22.03.2012 17:04:31 M J job_evsched_2
    26 22.03.2012 17:04:32 M J job_evsched_2
    27 22.03.2012 17:04:33 M J job_evsched
    28 22.03.2012 17:04:34 M J job_evsched_2
    29 22.03.2012 17:04:35 M J job_evsched_2
    30 22.03.2012 17:04:36 M J job_evsched_2
    31 22.03.2012 17:04:37 M J job_evsched
    32 22.03.2012 17:04:38 M J job_evsched_2
    h5.
    --test results #sleep-1#=5, #sleep-2#=1
    --jobs (job_evsched/job_evsched2) run alternately, only two events are enqued/processed
    ID SYS_DATE STATUS PROCESSED PROCESSED_BY
    41 22.03.2012 17:07:42 M J job_evsched_2
    42 (Null) M N (Null)
    43 (Null) M N (Null)
    44 (Null) M N (Null)
    45 (Null) M N (Null)
    46 (Null) M N (Null)
    47 22.03.2012 17:07:48 M J job_evsched
    48 (Null) M N (Null)
    */

    hi, thank you for your (fast) answer! that is the solution to my problem!
    now i have a follow-up question:
    i've got a procedure, that runs between 1 and 2 minutes long. unlimited running lightweight jobs
    would freeze the db...
    how can the count of the parallel running lightweight-jobs be limited?
    according to the documentation it is not possible:
    There is no explicit limit to the number of lightweight jobs that can run simultaneously to process multiple instances of the event.
    However, limitations may be imposed by available system resources.
    could you explain to me, what it (...available system recources...) means?
    eventually what i would like to have: max. two parallel running (lightweight) jobs....
    thank you in advance, bye, á
    ps: can i attach a file to the post anyway?
    Edited by: user4786904 on 23.03.2012 07:22

  • Calling batch file using dbms_scheduler

    Hello,
    i have created a schedule, program and a Job to using the DBMS_SCHEDULER. creates all those fine but when i try to run i get errors.
    here is the code:
    begin
    dbms_scheduler.create_schedule(
    schedule_name => 'dailyjob',
    repeat_interval => 'FREQ=DAILY; INTERVAL=1;
    BYDAY=TUE; BYHOUR=4',
    comments => 'schedule to run daily');
    dbms_scheduler.create_program
    ( program_name => 'runord',
    program_type => 'EXECUTABLE',
    program_action => 'd:\oracle\product\admin\scripts\ord.bat >nul',
    enabled => TRUE,
    comments => 'ORDERS.'
    dbms_scheduler.create_job (
    job_name=>'TEST',
    program_name =>'runord',
    schedule_name=> 'DAILYjob',
    enabled => true,
    comments => 'TESTING the Orders Job.'
    end;
    exec dbms_scherduler.run_job('TEST');
    gives me the errors.
    in the batch file i am calling connecting to the database and calling the sql file. is there any way that i can connect to the database directly from scheduler itself? i dont like to save username and passwords in a file to connect and invoke sqlplus?
    could any one help.....

    Pass them to the external command line as parameters? That exposes the name and password even more.
    We use a tightly controlled directory with this information in it and access to the directory is controlled. The scripts are also in a controlled directory and have read privileges where the credentials are stored.
    That way the scripts don't have the data exposed and don't use it until they run.

  • DBMS_SCHEDULER - ORA-02064: distributed operation not supported

    I am getting this error:
    ORA-02064: distributed operation not supported
    using the DBMS_SCHEDULER package in Database 10g. The code works successfully in PL/SQL DEVELOPER inside the database but when I try to run the code through PSP pages on the web, I get this error. The erro happens when this method is executed in DBMS_SCHEDULER:
    DBMS_SCHEDULER.CREATE_PROGRAM(
    PROGRAM_NAME => 'ROADS_FTP',
    PROGRAM_TYPE => 'STORED_PROCEDURE',
    PROGRAM_ACTION => 'pkg_report_t3.transfer_report',
    NUMBER_OF_ARGUMENTS => 0,
    ENABLED => FALSE,
    COMMENTS => 'Highway Driving Conditions FTP Program');
    Do anybody know how I can get this to work in a browser? Or why I am getting this error?
    Thanks!

    Agowda wrote:
    hi
    I'm just passing the values to the procedure .
    Procedure is stored on a remote machine
    procedure has a ddlAnd the DDL will implicitly issue a commit before and after that DDL statement (as all DDL statements do). So you ARE doing a commit in a romote procedure call, hence why you're getting the error.
    If you want to remotely create a user you need to issue the DDL in the manner I described.

  • How ro run unix script freom pl/sql - dbms_scheduler 11.2.0.3

    Hi,
    Using 11.2.0.3 and have a unix script which works fine.
    Want to run this unix script every time a piece of pl/sql runs
    have put below in but doesn't actually run it.
    How can we achieve this?
    Many Thanks
    idea is that file we create locqally on server is copied to another via the unix script caled form pl/sql
    DBMS_SCHEDULER.create_program (
       program_name => 'test_executable_prog',
       program_type => 'EXECUTABLE',
       program_action => '/oracle/jm/data/dataout/copy_tcfile',
       number_of_arguments => 0,
       enabled => TRUE,
       comments => 'CREATE_PROGRAM test using a schell script.');Tried below but no joy
    -- Shell Script (OS executable file).
    /*DBMS_SCHEDULER.drop_program(program_name => 'por_copy_files');
    DBMS_SCHEDULER.create_program (
       program_name => 'por_copy_files',
       program_type => 'EXECUTABLE',
       program_action => ' /oracle/jm/data/dataout/copy_tcfile',
       number_of_arguments => 0,
       enabled => TRUE,
       comments => 'CREATE_PROGRAM test using a schell script.');
    DBMS_SCHEDULER.create_job (
        job_name        => 'por_copy_files_job',
        program_name    => 'por_copy_files',
        start_date      => null,--SYSTIMESTAMP,
        repeat_interval => null,--'freq=hourly; byminute=0',
        end_date        => NULL,
        enabled         => TRUE,
        comments        => 'Job defined by existing program and inline schedule.');Edited by: user5716448 on 03-Oct-2012 08:35
    Getting message when look in all_scheduler_job_run_details
    ORA-27369: job of type EXECUTABLE failed with exit code: No such file or directory
    even thoug hfile exists
    Edited by: user5716448 on 03-Oct-2012 08:50

    When run for unix command line which o.k
    get
    AUTHSTATE=files
    A__z=! LOGNAME
    COLUMNS=132
    EDITOR=vi
    ENV=/home/oracle/.kshrc
    HOME=/home/oracle
    LANG=en_US
    LC__FASTMSG=true
    LOCPATH=/usr/lib/nls/loc
    LOGIN=oracle
    LOGNAME=oracle
    MAIL=/usr/spool/mail/oracle
    MAILMSG=[YOU HAVE NEW MAIL]
    MAIL_HOST=prdikw01
    NLSPATH=/usr/lib/nls/msg/%L/%N:/usr/lib/nls/msg/%L/%N.cat
    ODMDIR=/etc/objrepos
    ORACLE_BASE=/oracle/app/oracle
    ORACLE_HOME=/oracle/app/oracle/product/11.2.0/dbhome_1
    ORACLE_SID=IKW
    ORACLE_TERM=vt100
    ORATAB_PATH=/etc
    PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:/usr/java5/jre/bin:/usr/java5/bin:/usr/local/bin:/etc:/usr/sbin:/usr/ucb:/h
    ome/oracle/bin:/usr/bin/X11:/sbin:/oracle/app/oracle/product/11.2.0/dbhome_1/bin:/oracle/app/oracle/product/11.2.0/dbhome_1/OPatch
    PS1=[$ORACLE_SID]$PWD $
    PWD=/oracle/jm/data
    SHELL=/usr/bin/ksh
    TERM=xterm
    TMPDIR=/tmp
    TZ=GMT0BST,M3.5.0,M10.5.0
    USER=oracle
    _=/usr/bin/env
    dba=/home/oracle/dbaWhen run from pl/sql
    get
    ORA-27369: job of type EXECUTABLE failed with exit code: 255
    STANDARD_ERROR="execve: Exec format error"when try
    dbms_scheduler.create_job(
    job_name => 'POR_JOB',
    job_type => 'EXECUTABLE',
    job_action => '/oracle/jm/data/copy_tcfile',
    start_date => SYSTIMESTAMP,
    number_of_arguments=>0,
    enabled => true,
    auto_Drop => true,
    comments => 'Demo');Above code in pl/sql where create job and schedule job separately gives file not found message even though give full path

  • Schell Script to Schdule In Dbms_Schedule

    Hi All,
    I've a script to schedule in dbms_scheduler, here is the usage of script in linux command line..
    "/home/oracle/scripts/run.sh table_name"
    Any inputs how to schedule it in dbms scheduler daily to run 1200 AM

    @sushaant - the post you refer to has no relevance to using DBMS_SCHEDULER - it is just using a cron job to run a shell script.
    @Ramu - if the shell script is on the same server as the oracle database, you need to do the following
    1) Create a credential that has the unix user you want to run the script as.
    Note the script itself MUST set up any environment needed for the job to run - DBMS_SCHEDULER will not execute the .profile of the user you supply in the credential so don't assume in run.sh that any $PATH will exist or any other environment variables, you must set these explicitly. E.g. if you use a unix command, you should ensure you specify the full path to it in run.sh.
    BEGIN
    DBMS_SCHEDULER.CREATE_CREDENTIAL('YOUR_CREDENTIAL', 'username', 'password');
    END;
    2) In sqlplus, create a job with an external job that references run.sh and add argument. Change yourjob to be the job name
    you want to see when the job runs and your_table_name to the table that should be used in this particular job.
    dbms_scheduler.create_program(
    job_name=>'yourprogram',
    job_type=>'EXECUTABLE',
    job_action=>'/home/oracle/scripts/run.sh',
    number_of_arguments=>1);
    4) Create a job which links the program to the schedule and runs daily at midday and create other jobs for other tables giving them different parameters. If you have several of these to run but don't want them to run at the same time, look at the CREATE_CHAIN commands in the Oracle 11gR2 database admin guide as there are two whole chapters (28 & 29) on the scheduler ( http://docs.oracle.com/cd/E11882_01/server.112/e25494/scheduse.htm#i1033533 )
    BEGIN
    DBMS_SCHEDULER.CREATE_JOB (
    job_name => 'run_tablename1',
    program_name => 'yourprogram',
    repeat_interval => 'FREQ=DAILY;BYHOUR=12',
    credential_name => 'YOUR_CREDENTIAL',
    comments => 'Daily at noon');
    dbms_scheduler.set_job_argument_value@orl1(job_name=>'run_tablename1', argument_position=>1, argument_value='your_table_name');
    END;
    Note that as you are passing a table_name to the run.sh, i'm guessing it might be running some Oracle commands such as an analyse so if run.sh contains PLSQL commands, you could create a PLSQL package or procedure in the database and instead of creating an external program that runs a shells script, just run the PLSQL directly from DBMS_SCHEDULER. This is simpler as you don't need to create credentials etc.. needed for an external program.
    BEGIN
    DBMS_SCHEDULER.CREATE_PROGRAM (
    job_name => 'yourname',
    job_type => 'STORED_PROCEDURE',
    job_action => 'YOUR_PKG.DO_STUFF',
    start_date => '18-MAY-13 12.00.00 AM',
    repeat_interval => 'FREQ=DAILY', /* every day */
    end_date => '17-MAY-14 12.00.00 AM',
    auto_drop => FALSE,
    comments => 'My new job');
    END;
    dbms_scheduler.set_job_argument_value@orl1(job_name=>'yourjob',
    argument_position=>1, argument_value='your_table_name');
    and again create a chain if you want to run several when one completes.
    You need to select from various tables to see the result of the jobs and whether they succeed or not such as
    select * From user_scheduler_job_run_details where job_Name='run_tablename1'
    SELECT * FROM USER_SCHEDULER_JOB_LOG;
    select * from user_scheduler_running_jobs
    You can add email notifications using DBMS_SCHEDULER.ADD_JOB_EMAIL_NOTIFICATION
    See the admin guide for more details.

  • Create_program and asynchronous

    Hi,
    I'm new to dbms_scheduler, and am trying to determine how to set-up a job so that it runs every minute, regardless of whether the previous run is still running.
    Here is my simple test:
    create or replace procedure test_sleep
    as
    begin
    dbms_lock.sleep(180);
    end;
    begin
    dbms_scheduler.create_schedule(
    schedule_name => 'INTERVAL_EVERY_MINUTE',
    start_date => trunc(sysdate)+18/24;
    repeat_interval => 'freq=MINUTELY;interval=1',
    comments => 'Runtime:every day, every minute');
    end;
    begin
    dbms_scheduler.create_program(
    program_name => 'PROG_SLEEP',
    program_type => 'STORED_PROCEDURE',
    program_action => 'test_sleep',
    enabled => true,
    comments => 'Procedure to test async');
    end;
    begin
    dbms_scheduler.create_job(
    job_name => 'JOB_PROG_SLEEP',
    program_name => 'PROG_SLEEP',
    schedule_name => 'INTERVAL_EVERY_MINUTE',
    enabled => false,
    auto_drop => false,
    comments => 'Job to run test PROG_SLEEP every minute');
    end;
    begin
    dbms_scheduler.enable('JOB_PROG_SLEEP');
    end;
    /Then, when I query user_scheduler_job_run_details, I had expected to see an entry for every minute. Should I be looking elsewhere, or is this job only running every 180 seconds?
    -Thanks!

    Hi,
    This job will run every 180 seconds. In the Scheduler model a job is a single entity so multiple job runs will never overlap.
    However, on 11gR1 and higher, there is one exception which provides a way to do this. Event jobs can have the parallel_instances attribute set to true so that multiple runs will be allowed to overlap. So what you would need to do is to create an event based job that runs whenever an AQ (advanced queuing) message is enqueued and then another triggering job that runs once per minute and just enqueues an AQ message.
    Here is some code to get you started (this will only work on 11.1 and higher)
    Hope this helps,
    Ravi.
    <pre>
    set serveroutput on
    -- create a type for the queue, the queue table and the queue
    create or replace type q_type as object ( c1 varchar2(20) ) ;
    begin
    dbms_aqadm.create_queue_table
    queue_table => 'q_table',
    queue_payload_type => 'q_type',
    multiple_consumers => TRUE
    dbms_aqadm.create_queue ( queue_name => 'Q1', queue_table => 'q_table');
    dbms_aqadm.start_queue ( queue_name => 'Q1' ) ;
    exception when others then raise ;
    end ;
    -- create a utility procedure to enqueue into the queue
    -- once the job is enabled, this will cause the job to be run
    create or replace procedure enq_event as
    my_msgid RAW(16);
    props dbms_aq.message_properties_t;
    enqopts dbms_aq.enqueue_options_t;
    begin
    dbms_aq.enqueue('Q1', enqopts, props, q_type('IN'), my_msgid);
    commit;
    end;
    -- create a job that runs whenever the event occurs (and performs your action)
    begin
    dbms_scheduler.create_job(
    job_name => 'my_job',
    job_type => 'plsql_block',
    job_action => 'dbms_lock.sleep(180);',
    event_condition => 'tab.user_data.c1=''IN''',
    queue_spec => 'Q1',
    enabled => true);
    dbms_scheduler.set_attribute('my_job', 'parallel_instances', true);
    end;
    -- create a job that enqueues an event every minute
    begin
    dbms_scheduler.create_job(
    job_name => 'enq_event_job',
    job_type => 'plsql_block',
    job_action => 'enq_event',
    repeat_interval=>'freq=minutely',
    enabled => true);
    end;
    -- to cleanup execute the following statements
    -- exec dbms_aqadm.stop_queue('Q1')
    -- exec dbms_aqadm.drop_queue('Q1')
    -- exec dbms_aqadm.drop_queue_table('q_table')
    -- exec dbms_scheduler.drop_job('my_job',true);
    -- exec dbms_scheduler.drop_job('enq_event_job',true);
    -- drop procedure enq_event;
    -- drop type q_type;
    </pre>

  • Need help using dbms_scheduler to submit an immediate job on the database

    Hi. I need help using dbms_scheduler to submit an immediate job on the database. Essentially I want to issue a one-time call to an Oracle Stored Procedure - this procedure will then send an email. I've never used dbms_scheduler before, but here's what I have so far.
    So my Program is a stored database procedure named 'TTMS.dropperVacationConflict_Notify', but my problem is that I need to pass 3 parameter values to this job each time I run it. This is what I can't figure out. The procedure expects an 'Id' as number(5), begin_dt as a date, and end_dt as a date.
    How do I pass these values when I run my job? Can anyone help?
    begin
        dbms_scheduler.create_program(program_name=> 'PROG_DROPVACCONFLICTS_NOTIFY',
         program_type=> 'STORED_PROCEDURE',
         program_action=> 'TTMS.dropperVacationConflict_Notify',
         number_of_arguments => 3,
         enabled=>true,
         comments=> 'Procedure to notify PCM of a Dropper Vacation Conflict. Pass in Dropper Id, Begin_dt, and End_dt');
    end;
    begin
        dbms_scheduler.create_schedule
        (schedule_name=> 'INTERVAL_EVERY5_MINUTES',
         start_date=> trunc(sysdate)+18/24,
         repeat_interval => 'freq=MINUTELY;interval=5',
         end_date => null
         comments=> 'Runtime: Every day all 5 minutes, forever'
    end;
    begin
        dbms_scheduler.create_job
        (job_name => 'JOB_DROPVACCONFLICTS_NOTIFY',
         program_name => 'PROG_DROPVACCONFLICTS_NOTIFY',
         schedule_name => 'INTERVAL_EVERY5_MINUTES',
         enabled => true,
         auto_drop => true,
         comments => 'Job to notify PCM of Dropper Vacation Conflicts'
    end;
    /And I use this to execute the job as needed...
    begin
        dbms_scheduler.run_job('JOB_DROPVACCONFLICTS_NOTIFY',true);
    end;
    /

    Duplicate Post
    Need help using dbms_scheduler to submit an immediate job on the database

Maybe you are looking for