I want to create simple oracle sql dbms_scheduler.create_job to run sh file:
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'my_job1',
job_type => 'excecutable',
job_action => 'bin/some/some.sh',
enabled => TRUE,
comments => 'GOOD');
END;
Before starting some.sh I want to add parameteres to sh file:
echo sayHello from $argument_from_sql
How I can get "argument_from_sql" from Oracle sql when I am starting job. Where is any possibility?
You can pass arguments, for example
DBMS_SCHEDULER.create_job(
job_name=>'MY_SHELL',
job_type=>'EXECUTABLE',
job_action=>'/path/my_shell.sh',
enabled=>false
);
DBMS_SCHEDULER.set_job_argument_value('MY_SHELL',1,'myarg');
Related
I have a scheduled job that I am trying to update its job_action based on new requirements but the string now exceeds 4000 characters. Is there a way to allow the job_action to exceed 4000 characters without problems? Or what's the solution?
You must have scheduler with job_type as PLSQL_BLOCK, which allows 4000 characters in job_action.
If you want more than 4000 characters of code to execute in job than create the procedure with your code (which is more than 4000 characters) and then you need to alter the scheduler with job_type as STORED_PROCEDURE and job_action as your newly created procedure name.
Something like following(example from oracle docs):
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'update_sales',
job_type => 'STORED_PROCEDURE', -- change needed here in your case
job_action => 'OPS.SALES_PKG.UPDATE_SALES_SUMMARY', -- change needed here in your case
start_date => '28-APR-08 07.00.00 PM Australia/Sydney',
repeat_interval => 'FREQ=DAILY;INTERVAL=2', /* every other day */
end_date => '20-NOV-08 07.00.00 PM Australia/Sydney',
auto_drop => FALSE,
job_class => 'batch_update_jobs',
comments => 'My new job');
END;
/
Cheers!!
I Want to execute a Scheduler in Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
I have this package:
create or replace PACKAGE "S_IN_TDK" is
procedure parseMsg;
end;
and this job
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'parseMsg',
program_name => 'S_IN_TDK.parseMsg',
repeat_interval => 'FREQ=SECONDLY;INTERVAL=10',
--job_style => 'LIGHTWEIGHT',
comments => 'Job that polls device n2 every 10 seconds');
END;
but when I run the job I got this error:
Fallo al procesar el comando SQL
- ORA-27476: "S_IN_TDK.PARSEMSG" does not exist
ORA-06512: at "SYS.DBMS_ISCHED", line 185
ORA-06512: at "SYS.DBMS_SCHEDULER", line 486
ORA-06512: at line 2
I also tried
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'parseMsg',
job_action => 'begin S_IN_TDK.parseMsg; end;',
repeat_interval => 'FREQ=SECONDLY;INTERVAL=10',
--job_style => 'LIGHTWEIGHT',
comments => 'Job that polls device n2 every 10 seconds');
END;
but then I got this error:
Informe de error -
ORA-06550: line 2, column 3:
PLS-00306: wrong number or types of arguments in call to 'CREATE_JOB'
ORA-06550: line 2, column 3:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
Parameter program_name expects the name of a scheduler PROGRAM object. If you want to run an inline program then do use job_action parameter instead:
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'parseMsg',
job_action => 'begin S_IN_TDK.parseMsg; end;',
repeat_interval => 'FREQ=SECONDLY;INTERVAL=10',
--job_style => 'LIGHTWEIGHT',
comments => 'Job that polls device n2 every 10 seconds');
END;
Note that job_action expects a complete PL/SQL block as input.
DBMS_SCHEDULER.CREATE_JOB has three required parameters: job_name, job_type, and job_action. Add job_type => 'PLSQL_BLOCK', and also add enabled => true, to make the job run immediately.
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'parseMsg',
job_type => 'PLSQL_BLOCK',
job_action => 'begin S_IN_TDK.parseMsg; end;',
repeat_interval => 'FREQ=SECONDLY;INTERVAL=10',
--job_style => 'LIGHTWEIGHT',
enabled => true,
comments => 'Job that polls device n2 every 10 seconds');
END;
/
Use this query to check the job status:
select *
from dba_scheduler_job_run_details
where job_name = 'PARSEMSG'
order by log_date desc;
I am trying to create a simple scheduled event in an oracle 10g database. I have been trying to use dbms_scheduler.create_job. Here is the script I wrote:
begin dbms_scheduler.create_job (
job_name => 'disengagementChecker',
job_type => 'PLSQL_BLOCK',
job_action => 'INSERT INTO
PatientClassRelObs(patientClassID,observationTypeID) VALUES (1, 11)',
start_date => SYSDATE,
repeat_interval => 'FREQ=MINUTELY;INTERVAL=1',
comments => 'Iam tesing scheduler'); end;
When I run this, oracle throws these errors
ORA-06550: line 15, column 3:
PLS-00103: Encountered the symbol
"end-of-file" when expecting one of the following:
; The symbol
";" was substituted for "end-of-file" to continue.
I don't understand whats causes this error. Do you know what causes this error? Or why this is happening?
Thank you in advance!
-David
JOB_ACTION must be a valid PL/SQL block, not just a valid SQL statement. Use this:
job_action => '
BEGIN
INSERT INTO PatientClassRelObs(patientClassID,observationTypeID)
VALUES (1, 11);
END;',
UPDATE
Maybe this is a problem with a specific environment or some code not posted. To troubleshoot, start with something that's known to work, and add one small change at a time until something breaks.
Start with this code, using SQL*Plus.
SQL> begin
2 dbms_scheduler.create_job(
3 job_name => 'TEST_JOB',
4 job_type => 'PLSQL_BLOCK',
5 job_action => 'BEGIN NULL; END;',
6 start_date => systimestamp,
7 enabled => true);
8 end;
9 /
PL/SQL procedure successfully completed.
SQL> select status, log_date from dba_scheduler_job_run_details where job_name = 'TEST_JOB';
STATUS LOG_DATE
------------------------------ ---------------------------------------------------------------------------
SUCCEEDED 26-MAR-14 11.37.59.533000 PM -05:00
Created job like below :
BEGIN
Dbms_Scheduler.create_job(
job_name => 'PROECSS_STATE'
,job_type => 'STORED_PROCEDURE'
,job_action => 'ARCHIVE_AND_DELETE' -- Procedure Name
,start_date => SYSDATE
,repeat_interval => 'freq=DAILY; byhour=13' --Added byhour
,enabled => TRUE
,comments => 'job schedule for archiving process_state');
END;
When i created the job, the time was "21-mrt-2014 12:55:55"
But nothing has happened after checking( Checked at 13:05:45).
Procedure did not run as expected.
Can any one please tell me why job has not been executed?
Replace start_date => SYSDATE with start_date => SYSTIMESTAMP.
This is only a problem on some problems. For example, the code below runs 2 jobs on Oracle 12c on Windows, but only runs the first job on 11gR2 on Solaris.
begin
dbms_scheduler.create_job('TEST_JOB1', 'PLSQL_BLOCK', 'begin null; end;'
,start_date => systimestamp, enabled => true);
dbms_scheduler.create_job('TEST_JOB2', 'PLSQL_BLOCK', 'begin null; end;'
,start_date => sysdate , enabled => true);
end;
/
--Only one job ran (on some platforms).
select * from dba_scheduler_job_run_details where job_name like 'TEST%';
I do not know why this happens. I would appreciate it if anyone could explain it.
I have the following error in PL/SQL. I am not able to know what the error is. Please help me.
SQL> BEGIN
2 DBMS_SCHEDULER.CREATE_JOB
3 (
4 JOB_NAME => 'TESTINGFILE'
5 ,COMMENTS =>'TEST'
6 );
7 END;
8 /
DBMS_SCHEDULER.CREATE_JOB
*
ERROR at line 2:
ORA-06550: line 2, column 1:
PLS-00306: wrong number or types of arguments in call to 'CREATE_JOB'
ORA-06550: line 2, column 1:
PL/SQL: Statement ignored
According to the DBMS_Scheduler.Create_Job documentation, the procedure requires the job_name, job_type and job_action parameters. You've only specified job_name so you need to define the other two.
You can find DBMS_Scheduler.Create_Job examples here, here, and elsewhere.
This worked for me. I'm new to scheduling jobs but I came across this post while I was troubleshooting mine so I figured it would be good to share once I worked it out.
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'NAME_OF_PROCEDURE_JOB',
job_type => 'STORED_PROCEDURE',
job_action => 'NAME_OF_PROCEDURE',
number_of_arguments => 0,
repeat_interval => 'FREQ=DAILY;BYHOUR=23;BYMINUTE=30;',
start_date => SYSTIMESTAMP,
enabled => TRUE,
auto_drop => FALSE,
comments => 'Schedules a job to run NAME_OF_PROCEDURE at 11:30 everyday'
);
END;