Create a job using dbms_schedule.create_job
Hi, can someone assist me in coming up with an automated job to run the this code on Oracle 11g. Thanks In advance.
CREATE OR REPLACE PROCEDURE PR_SEND_EMAIL
( p_from_email_address VARCHAR2
, p_to_email_address VARCHAR2
, p_smtp_host VARCHAR2
, p_subject VARCHAR2
, p_message VARCHAR2
IS
/*Your query as cursor */
CURSOR emp_cur IS
SELECT * FROM a_tre_alert;
/*UTL_SMTP related varriavles. */
v_connection_handle UTL_SMTP.CONNECTION;
/* This send_header procedure is written in the documentation */
PROCEDURE send_header(pi_name IN VARCHAR2, pi_header IN VARCHAR2) AS
BEGIN
UTL_SMTP.WRITE_DATA(v_connection_handle, pi_name || ': ' || pi_header || UTL_TCP.CRLF);
END;
BEGIN
/*UTL_SMTP related coding. */
v_connection_handle := UTL_SMTP.OPEN_CONNECTION(host => p_smtp_host);
UTL_SMTP.HELO(v_connection_handle, p_smtp_host);
UTL_SMTP.MAIL(v_connection_handle, p_from_email_address);
UTL_SMTP.RCPT(v_connection_handle, p_to_email_address);
UTL_SMTP.OPEN_DATA(v_connection_handle);
send_header('From', '"Sender" <' || p_from_email_address || '>');
send_header('To', '"Recipient" <' || p_to_email_address || '>');
send_header('Subject', p_subject);
--MIME header.
UTL_SMTP.WRITE_DATA(v_connection_handle, 'MIME-Version: 1.0' || UTL_TCP.CRLF);
UTL_SMTP.WRITE_DATA(v_connection_handle, 'Content-Type: multipart/mixed; ' || UTL_TCP.CRLF);
UTL_SMTP.WRITE_DATA(v_connection_handle, ' boundary= "' || 'SAUBHIK.SECBOUND' || '"' || UTL_TCP.CRLF);
UTL_SMTP.WRITE_DATA(v_connection_handle, UTL_TCP.CRLF);
-- Mail Body
UTL_SMTP.WRITE_DATA(v_connection_handle, '--' || 'SAUBHIK.SECBOUND' || UTL_TCP.CRLF);
UTL_SMTP.WRITE_DATA(v_connection_handle, 'Content-Type: text/plain;' || UTL_TCP.CRLF);
UTL_SMTP.WRITE_DATA(v_connection_handle, ' charset=US-ASCII' || UTL_TCP.CRLF);
UTL_SMTP.WRITE_DATA(v_connection_handle, UTL_TCP.CRLF);
UTL_SMTP.WRITE_DATA(v_connection_handle, p_message || UTL_TCP.CRLF);
UTL_SMTP.WRITE_DATA(v_connection_handle, UTL_TCP.CRLF);
UTL_SMTP.WRITE_DATA(v_connection_handle,'Due Date--Amount--State--ChkSerial--APSerial--AccountCode--FloatAccount'|| UTL_TCP.CRLF);
FOR i IN emp_cur
LOOP
UTL_SMTP.WRITE_DATA(v_connection_handle, i.chequedate || '--' || i.rialamount || '--' || i.state || '--' || i.check_serial || '--' || i.ap_serial || '--' || i.acc_code || '--' || i.facc_code || UTL_TCP.CRLF);
END LOOP;
UTL_SMTP.WRITE_DATA(v_connection_handle, UTL_TCP.CRLF);
-- Close Email
UTL_SMTP.WRITE_DATA(v_connection_handle, '--' || 'SAUBHIK.SECBOUND' || '--' || UTL_TCP.CRLF);
UTL_SMTP.WRITE_DATA(v_connection_handle, UTL_TCP.CRLF || '.' || UTL_TCP.CRLF);
UTL_SMTP.CLOSE_DATA(v_connection_handle);
UTL_SMTP.QUIT(v_connection_handle);
EXCEPTION
WHEN OTHERS THEN
UTL_SMTP.QUIT(v_connection_handle);
RAISE;
END;
CREATE OR REPLACE PUBLIC SYNONYM PR_SEND_EMAIL1 FOR PR_SEND_EMAIL;
BEGIN
PR_SEND_EMAIL ( p_from_email_address => '[email protected]'
, p_to_email_address => [email protected]'
, p_smtp_host => 'xxx.xxx.xxx.xx'
, p_subject => 'FNC_TR_1 Daily Checks Due'
, p_message => 'The following is the list of checks that are due in the next 7 days'
EXCEPTION WHEN OTHERS
THEN DBMS_OUTPUT.PUT_LINE('ERROR in Procedure PR_SEND_EMAIL - ' || SQLERRM);
RAISE;
END;
What help do you need? There are tons of documentation and examples. Is this not helpful?
Examples of Using the Scheduler
ORACLE-BASE - Scheduler (DBMS_SCHEDULER) Enhancements in Oracle Database 11g Release 1
DBMS_SCHEDULER
Similar Messages
-
Job scheduling using dbms_scheduler.create_job
hi all experts,
i am really grateful to you for your responses, now have a look at this, i have created a job with "dbms_scheduler.create_job" and blow is the output from view "dba_schduler_jobs" why it is showing run_count to '0'...i have gone through all provided links like:
Answers to "Why are my jobs not running?"
and applied and checked all parameters, i am using oracle 10.2.0.1.0 on windows server 2003 32-bit
SQL> BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'clouser'
,job_type => 'PLSQL_BLOCK'
,job_action => 'begin package.procedure("po_closure"); end;'
,start_date => to_date('17-04-2009 22:00:00', 'dd-mm-yyyy hh24:mi:ss')
,repeat_interval => 'FREQ=DAILY;byminute=10'
,enabled => TRUE
,comments => 'op closure everyday at 11PM'
END;
PL/SQL procedure successfully completed.
SQL> select owner,job_name name,run_count run,start_date
2 from dba_scheduler_jobs
3 where owner='FINANCEDEV';
OWNER NAME RUN
START_DATE
FINANCEDEV CLOUSER 0
17-APR-09 02.45.10.000000 PM +05:30
FINANCEDEV CLOUSER_MAIN 0
18-APR-09 10.25.00.000000 AM +05:30
FINANCEDEV CLOUSER_MAIN1 0
18-APR-09 10.45.00.000000 AM +05:30
OWNER NAME RUN
START_DATE
FINANCEDEV CLOUSER_MAIN4 0
18-APR-09 10.45.00.000000 AM +05:30
FINANCEDEV CLOUSER_MAIN5 0
18-APR-09 10.43.00.000000 AM +05:30the time i scheduled has already passed, and i am checking it again and again, but no luck,can you please explain why is it so??
thanks in advance
thanks and regards
VD
Edited by: vikrant dixit on Apr 17, 2009 10:33 PMHello,
I should have asked only for next_run_date and state and failure_count. Do you see any value for failure_count column. Seems you have a failure in running of this job and whereever are you , what's the time?
You can also run this job manually using and see if run_count goes up or failure and it schedules the job for tommorrow as well.
exec DBMS_SCHEDULER.RUN_JOB('CLOUSER',TRUE);Based on your information, your next_run_date should be set to 19 APr @ 12:10 AM.
Here is example based on your information
BEGIN
sys.DBMS_SCHEDULER.create_job (
job_name => '"SCHEMA_NAME"."CLOUSER"',
job_type => 'PLSQL_BLOCK',
job_action => 'DECLARE
begin
po_closure varchar2(..) := ''some_value'';
schema_name.package_name.procedure(po_closure);
commit;
end;
repeat_interval => 'FREQ=DAILY;BYMINUTE=10;BYSECOND=0',
start_date => SYSTIMESTAMP AT TIME ZONE 'US/Eastern',
job_class => 'DEFAULT_JOB_CLASS',
auto_drop => FALSE,
enabled => TRUE
sys.DBMS_SCHEDULER.set_attribute (name => '"SCHEMA_NAME"."CLOUSER"',
attribute => 'restartable',
VALUE => TRUE);
sys.DBMS_SCHEDULER.enable ('"SCHEMA_NAME"."CLOUSER"');
END;Regards -
Getting error while trying to execute a external job using dbms_scheduler
Hello,
I create a job using alpha account.
begin
dbms_scheduler.create_job(
job_name => 'jps_test_executable',
job_type => 'EXECUTABLE',
job_action => '/usr/bin/ksh',
number_of_arguments => 2
dbms_scheduler.set_job_argument_value (
job_name => 'jps_test_executable',
argument_position => 1,
argument_value => '/tmp/abc.sh'
and when I execute the job in the schema using alpha account it works fine.
BEGIN
DBMS_SCHEDULER.run_job (job_name => 'jps_test_executable',
use_current_session => FALSE);
END;
Works fine.
But if I try to execute the same job using some other account say beta in the same schema , I am getting error
ORA-27476 :”SMS.RUN_SMS_JOBS Does not exist ORA-06512 at “SYS.DBMS_ISCHED” line 2793 ORA-06512 :at “SYS.DBMS_SCHEDULER”,line 1794
even I give the fill qualifier, still I am getting the error.
BEGIN
DBMS_SCHEDULER.run_job (job_name => 'alpha.jps_test_executable',
use_current_session => FALSE);
END;
Any help will be appreciated.
Thank you,
RajIt's the expected behavior:
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_sched.htm#CIHHBGGI
RUN_JOB requires that you be the owner of the job or have ALTER privileges on that job. You can also run a job if you have the CREATE ANY JOB privilege.So, you need to grant the required privilege:
aplha@orcl> grant alter on alpha.jps_test_executable to beta;HTH
Enrique
PS If your problem was solved consider marking the question as answered. -
How to run the job using DBMS_SCHEDULER
How to run the job using DBMS_SCHEDULER
pleas give some sample Iam very new to DBMS_SCHEDULERHi
DBMS_SCHEDULER
In Oracle 10g the DBMS_JOB package is replaced by the DBMS_SCHEDULER package. The DBMS_JOB package is now depricated and in Oracle 10g it's only provided for backward compatibility. From Oracle 10g the DBMS_JOB package should not be used any more, because is could not exist in a future version of Oracle.
With DBMS_SCHEDULER Oracle procedures and functions can be executed. Also binary and shell-scripts can be scheduled.
Rights
If you have DBA rights you can do all the scheduling. For administering job scheduling you need the privileges belonging to the SCHEDULER_ADMIN role. To create and run jobs in your own schedule you need the 'CREATE JOB' privilege.
With DBMS_JOB you needed to set an initialization parameter to start a job coordinator background process. With Oracle 10g DBMS_SCHEDULER this is not needed any more.
If you want to user resource plans and/or consumer groups you need to set a system parameter:
ALTER SYSTEM SET RESOURCE_LIMIT = TRUE;
Baisc Parts: Job
A job instructs the scheduler to run a specific program at a specific time on a specific date.
Programs
A program contains the code (or reference to the code ) that needs to be run to accomplish a task. It also contains parameters that should be passed to the program at runtime. And it?s an independent object that can referenced by many jobs
Schedules
A schedule contains a start date, an optional end date, and repeat interval with these elements; an execution schedule can be calculated.
Windows
A window identifies a recurring block of time during which a specific resource plan should be enabled to govern resource allocation for the database.
Job groups
A job group is a logical method of classifying jobs with similar characteristics.
Window groups
A window groups is a logical method of grouping windows. They simplify the management of windows by allowing the members of the group to be manipulated as one object. Unlike job groups, window groups don?t set default characteristics for windows that belong to the group.
Using Job Scheduler
SQL> drop table emp;
SQL> Create table emp (eno int, esal int);
SQL > begin
dbms_scheduler.create_job (
job_name => 'test_abc',
job_type => 'PLSQL_BLOCK',
job_action => 'update emp set esal=esal*10 ;',
start_date => SYSDATE,
repeat_interval => 'FREQ=DAILY; INTERVAL=10',
comments => 'Iam tesing scheduler');
end;
PL/SQL procedure successfully completed.
Verification
To verify that job was created, the DBA | ALL | USER_SCHEDULER_JOBS view can be queried.
SQL> select job_name,enabled,run_count from user_scheduler_jobs;
JOB_NAME ENABL RUN_COUNT
TEST_abc FALSE 0
Note :
As you can see from the results, the job was indeed created, but is not enabled because the ENABLE attribute was not explicitly set in the CREATE_JOB procedure.
Run your job
SQL> begin
2 dbms_scheduler.run_job('TEST_abc',TRUE);
3* end;
SQL> /
PL/SQL procedure successfully completed.
SQL> select job_name,enabled,run_count from user_scheduler_jobs;
JOB_NAME ENABL RUN_COUNT
TEST_ABC FALSE 0
Copying Jobs
SQL> begin
2 dbms_scheduler.copy_job('TEST_ABC','NEW_TEST_ABC');
3 END;
4 /
PL/SQL procedure successfully completed. Hope it will help you upto some level..!!
Regards
K -
Error in creating job using DBMS_SCHEDULER
I have create the following procedure to create individual jobs dynamically on each schema.
CREATE OR REPLACE PROCEDURE APSP.JOB_TEST_RAM
AS
V_SQL VARCHAR2 (1000);
BEGIN
FOR i
IN (SELECT gbm.OWNER_NAME owner_name,
vdb.NAME || '_BU_' || gbm.BU_CODE,
gbm.bu_id bu_id
FROM apps_global.GLOBAL_BU_MAPPING gbm, v$database vdb
WHERE OWNER_NAME NOT IN ('APPS_GLOBAL'))
LOOP
V_SQL :=
'BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => '''
|| i.owner_name
|| '_archive_job'',
job_class => '''
|| i.owner_name
|| '_job_class'',
job_type => ''PLSQL_BLOCK'',
job_action => ''begin APSP.POP_TARGET(''APPS_XX'',i.owner,i.buid); end;'',
auto_drop => TRUE,
comments => '''|| i.owner_name||''',
enabled => TRUE);
END;';
EXECUTE IMMEDIATE V_SQL;
END LOOP;
END;
/The procedure is having following arguments.
CREATE OR REPLACE PROCEDURE APSP.POP_TARGET (
p_schema_name VARCHAR2,
p_actual_schema_name VARCHAR2,
p_buid NUMBER
)While executing this procedure I am getting the below error.
PLS-00103: Encountered the symbol "APPS_XX" when expecting one of the following:
Please help me.
Thanks in advance .Try this
create or replace procedure apsp.job_test_ram
as
v_sql varchar2 (1000);
begin
for i
in (select gbm.owner_name owner_name,
vdb.name || '_BU_' || gbm.bu_code,
gbm.bu_id bu_id
from apps_global.GLOBAL_BU_MAPPING gbm, v$database vdb
where owner_name not in ('APPS_GLOBAL'))
loop
v_sql :=
q'[begin
dbms_scheduler.create_job
job_name => '#OWNER_NAME#_archive_job'
, job_class => '#OWNER_NAME#_job_class'
, job_type => 'STORED_PROCEDURE'
, job_action => q'{APSP.POP_TARGET('APPS_XX','#OWNER_NAME#','#BUILD#')}'
, auto_drop => TRUE
, comments => '#OWNER_NAME#'
, enabled => TRUE
end;]';
v_sql := replace(replace(v_sql, '#OWNER_NAME#', i.owner), '#BUILD#', i.build);
execute immediate v_sql;
end loop;
end;
/ -
Creating backup Job with DBMS_SCHEDULER
Hello,
Can someone please help me out here:
I'm using Oracle10g release 1 on windowsXP
I'm trying to create a backup job with dbms_scheduler and it's not working.
This is what I did:
I created a job as follows:
BEGIN
dbms_scheduler.create_job (
job_name => 'RMAN_FULL',
job_type => 'EXCUTABLE',
job_action => 'E:\wkdir\rman_bkp',
enabled => TRUE,
start_date => '24-NOV-2007 2:10:00 PM',
repeat_interval => 'FREQ=WEEKLY',
comments => 'Full Database Backup');
END;
While rman_bkp is an RMAN command but it wasn't working.
Please where do I get it wrong?
Kindly put me through the EXECUTABLE or should I use PL/SQL_BLOCK and how?
Thanks.
Regards,
CherishHi,
There is a guide to running external jobs using the Scheduler here
Guide to External Jobs on 10g with dbms_scheduler e.g. scripts,batch files
You need to use the full path to a real Windows executable and the arguments to it e.g. for a batch script you would have to do something like
c:\windows\cmd.exe /q /c c:\myscript.bat
There is a forum dedicated to the Scheduler here
Scheduler
Hope this helps,
Ravi. -
How to use dbms_Scheduler.Create_Job from within stored procedure?
Hello,
using 10g (10.1.0.2.0) on Windows 2000 I had problems to create scheduler jobs from within a stored procedure (see example below). What easily succeeds using anonymous blocks failed when calling from a stored procedure, due to ORA-27486. Only when I compile the procedure with invoker's rights the call to dbms_Job.Create_Job is successfull!? From my knowledge there is no difference between invoker's and definer's rights, if I compile and call with the same user, is there?
Does anyone know the reason for this behaviour or is it simply a bug?
Have a nice day.
Björn Hachmann
Hamburg / Germany
-- Example start.
create table t
a number(1),
b date default sysdate
create or replace procedure sched1
is
begin
dbms_scheduler.create_job(
job_name => 'TEST_JOB1',
job_type => 'PLSQL_BLOCK',
job_action => 'BEGIN insert into t values (1); END;',
repeat_interval => 'freq=secondly',
enabled => TRUE
commit;
end;
create or replace procedure sched2
authid current_user
is
begin
dbms_scheduler.create_job(
job_name => 'TEST_JOB2',
job_type => 'PLSQL_BLOCK',
job_action => 'BEGIN insert into t values (2); END;',
repeat_interval => 'freq=secondly',
enabled => TRUE
commit;
end;
exec sched1; -- This call fails with ORA-27486.
exec sched2; -- This call succeeds!
/* Cleanup.
exec dbms_scheduler.drop_job('TEST_JOB1', true);
exec dbms_scheduler.drop_job('TEST_JOB2', true);
drop table t;
*/Your example code ran without problems for me on 10.1.0.3.0 so it probably is a bug.
-
Any way to find out which program has created a job using 'JOB_OPEN'?
Hi,
I have some jobs created by some program. The job is incomplete, i.e., the programs which created the job just used 'JOB_OPEN' and it doesn't have any steps.
Is there any way to find out which program created that incomplete job?
Thanks in advance.
Regards,
Arun MohanNot sure but try this FM
BP_JOB_SELECT -Returns a table with job(s) details .
кu03B1ятu03B9к
Edited by: kartik tarla on Dec 30, 2008 6:50 PM -
Error While creating a Job using JOB_OPEN
Hello,
I am trying to create a job in the output type of a standard transaction.
But the job creation is failing. While debugging the transaction in update mode, I found out that the JOB_OPEN is coming out in the 'COMMIT WORK'.
Is there any other way to create a job so that the program executes properly.
Thanis/Regards,
Abhijit Anandgaonkar.Hi,
create a RFC function module....and inside the function module...create the batch job..
in the output type processing program...call the RFC function module in background task..
Thanks
Naren -
Creating a job with DBMS_SCHEDULE from Forms?
I'm new to DBMS_SCHEDULER. I'd like to run a stored procedure from an Oracle Forms application passing some parameters from the Form to the procedure, then immediately running the procedure and after the procedure has finished dropping it from the job list. The procedure may take some time to run and the user doesn't want to wait before exiting the form. Can this be done?
Sure, no problem. The job will be dropped after termination by default (autodrop). If privileges are ok it should work. Things to think about are error reporting and retries.
regards,
Ronald
http://ronr.nl/unix-dba -
Creating JOB using JOB API - Future Dated value for a segment
Hi
Trying to create a JOB using "hr_job_api.create_job" as of today (17-Jul-2009), with one of the segment value has the 'Date_from' as 26-Jul-2009.
API is throwing the below error
ORA-20001: FLEX-VALUE IS EXPIRED:
ORA-06512: at "APPS.HR_JOB_API", line 878
Have anyone come across this error before ?
Thanks
ArunAs per the error it saying there is a problem in the DFF attached with the job, or even job kff itself, paste the whole code and whole error
-
Error creating job into trigger using DBMS_SCHEDULER.
Hi,
I am trying to create job using dbms_scheduler package. I have one trigger on insert event on one table. I am creating job using following syntax.
CREATE OR REPLACE TRIGGER TRG_BI_JOB_CONFIG BEFORE INSERT ON JOB_CONFIG FOR EACH ROW
DECLARE
BEGIN
DBMS_SCHEDULER.Create_Job(job_name => 'my_job1'
,job_type => 'PLSQL_BLOCK'
,job_action => 'delete_temp'
,start_date => TO_DATE('15-JUL-2003 1:00:00 AM', 'dd-mon-yyyy hh:mi:ss PM')
,repeat_interval => 'FREQ=DAILY'
,enabled => TRUE
,comments => 'DELETE FOR job schedule.');
EXCEPTION
WHEN OTHERS THEN RAISE;
END;
but I am getting following error while inserting into JOB_CONFIG table.
ORA-04092: cannot in a trigger
ORA-06512: at "PRAKASH1.TRG_BI_JOB_CONFIG", line 41
ORA-04088: error during execution of trigger
same above statement If I am running from sqlplus then It is creating job without error. If I am creating job using DBMS_JOB into trigger then It is also working fine but this package is depricated from oracle10g so I cannt use it any more.
My Oracle version is 'Oracle DATABASE 10g RELEASE 10.2.0.1.0 - Production'.
can anyone help me in this context.I have a few comments on this thread as an Oracle dbms_scheduler developer.
- Oracle takes backward compatibility very seriously. Although dbms_job is deprecated, the interface will continue to work indefinitely. The deprecation of dbms_job is so that customers will be encouraged to take advantage of the more powerful dbms_scheduler. It is extremely unlikely that entire blocks of functionality will ever be removed. There is currently no plan to remove dbms_job functionality (and even if there were, doing so would be strenuously opposed by many users).
- lots of internal Oracle database components are standardizing on using dbms_scheduler (resource manager, materialized views, auto sql tuning etc). This is good evidence that it will continue to be the recommended scheduling method for the foreseeable future - not even the concept of a replacement exists. It is also under active development.
- The reason for the automatic commit is that a dbms_scheduler job is a full database object like a stored procedure or a table. So a call to dbms_scheduler.create_job is like executing a DDL which takes effect immediately. A dbms_job job is mostly just a row in a table so a call to dbms_job.submit behaves like regular DML. There are many advantages to a job being a full database object but DDL behaviour is an unfortunate requirement of this.
Hope this clears a few things up, reply with any questions.
-Ravi -
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; -
Using DBMS_Scheduler Package
Hi All,
I am on the way to use Oracle's Scheduler component. Please guide me how to associate a job or job class with a window or window group.
Job classes are used for prioritizing jobs and group jobs which have common resource requirements. Similarly, windows are used for automatically switching resource plans.
Now I am confused how can I attach my jobs (and job classes) with a window.
Is window associated with the help of schedules ?
Thnks and Regards,
NeerajHi.
Using DBMS_SCHEDULER.CREATE_JOB creates the job. You can assign a schedule to the job when it is created. The inparameter schedule_name is used. When creating the window, the procedure dbms_scheduler.create_window takes some in parameters. One of these is Schedule_name. So Job is connected to a schedule and a schedule is connected to a window.
Hopes this helps.
rgds
Kjell -
ORA-01422: while trying to create a job
Hi all,
WE need a help from you, group of experts
we are getting the following error
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at "SYS.DBMS_ISCHED", while trying to create a job using the following code
BEGIN
DBMS_SCHEDULER.create_program
(program_name => 'FAILURE_MONITOR_PRG',
program_action => 'JOB_MGR.SPR_FAILURE_MONITOR',
program_type => 'STORED_PROCEDURE',
number_of_arguments => 1,
enabled => FALSE
DBMS_SCHEDULER.define_metadata_argument
(program_name => 'FAILURE_MONITOR_PRG',
argument_position => 1,
metadata_attribute => 'EVENT_MESSAGE'
DBMS_SCHEDULER.create_job
(job_name => 'FAILURE_MONITOR_JOB',
program_name => 'FAILURE_MONITOR_PRG',
enabled => TRUE,
auto_drop => FALSE,
start_date => SYSDATE,
event_condition => 'tab.user_data.event = ''FAILED''',
queue_spec => 'event_queue'
END;
Oracle allows us to create the job if the parameter values for enabled is "false" in the DBMS_SCHEDULER.create_job call. But we got the same error
when tried to enable the job using exec DBMS_SCHEDULER.ENABLE ('FAILURE_MONITOR_JOB');
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at "SYS.DBMS_ISCHED", line 2751
ORA-06512: at "SYS.DBMS_SCHEDULER", line 1794
ORA-06512: at line 1
Please help us to solve this issue
Thanks,
Reghu
nullHi Ravi,
Thank you for your kind support
That issue has been solved. Problem was with the event queue and only for that particular job i mentioned in the first post (I was able to create other jobs with different Events using the same queue) . After recreating the event queue i am able to create the same job. I got the same error when I tired to drop the queue, and then I dropped the queue table itself. Do you have any idea about what might had caused the issue?
Thanks
Reghu
Maybe you are looking for
-
My MacBook Pro (15-inch Mid 2009) question mark on startup
My MacBook Pro (15-inch Mid 2009) has a question mark on startup. I brought it to my local apple service centre and they told me that after a few tests it was the hardrive, so they changed it under-warranty. Back home I started re-installing my syste
-
Adobe Photoshop CS4 or Lightroom?
I am very new to the photoshop programs and was wondering if I could get anyones opinion. I have a windows XP computer and want to be able to do some photoshopping/editing on photos that take with my Canon XSi. I was told that Lightroom 2 is all I'
-
1.5.1 Opening File in PlsqlNode incorrectly displays a default connection
SQL Developer 1.5.1.54.40, JDK 1.6.0_04, Win XP SP 2 I have just noticed that opening a file as a PlsqlNode (based on file type preferences) displays a default connection (the connection for the current tab). However, when compiling, you are prompted
-
Dynamics CRM 2015 developer Class
I am looking for a Dynamics CRM 2015 developer taining/class. My company will pay for the course and I am located in Washington, DC/Virginia./Maryland area. Any in class recommendations?
-
If you're having trouble with Audio with Movies or Netflix, try this...
Go to general> settings> audio and turn Dolby Digital to 'off', Then unplug your Apple TV for 20 seconds and try again. Should do the trick. Worked for me after talking to Apple Support.