Using PL / SQL Expressions in repeat_interval Oracle 11g DBMS_SCHEDULER

I am trying to set the PL / SQL expression as REPEAT_INTERVAL of my work - unfortunately, it does not work.

I would like to include a CASE expression during such an interval, for example, how to set the repeat interval for a job starts at the full minute, say, at 14:17:00, and if it is executed for a minute, it starts after 30 seconds the next time, and if it starts at an odd minute, it starts the next minute, so part of the execution schedule will look like this:

14:17:00
14:18:00
14:18:30
14:19:00
14:20:00
14:20:30
14:21:00

etc. I tried with these expressions:

trunc(sysdate, 'MI') + CASE WHEN mod(to_number(to_char(sysdate, 'MI')), 2)=0 then (1/24/60/2) else (1/24/60) end case
SYSTIMESTAMP + CASE WHEN mod(to_number(to_char(sysdate, 'MI')), 2)=0 then INTERVAL '30' SECOND else INTERVAL '60' SECOND end case

both of them work in SQL query, but I can not compile JOB. What should a PL / SQL expression look like?

, JOB ? , , - , , .

+3
2

, ,

  • ; , .

:

BEGIN
  dbms_scheduler.create_schedule('embed_sched', repeat_interval =>
    'FREQ=YEARLY;BYDATE=0130,0220,0725');
  dbms_scheduler.create_schedule('main_sched', repeat_interval =>
    'FREQ=MONTHLY;INTERVAL=2;BYMONTHDAY=15;BYHOUR=9,17;INCLUDE=embed_sched');
END;
+3

, , , . plssql :

: 11.2.0.3.0

. my_schedules.odd_even current_date + 30 , 1 , :

    CREATE OR REPLACE package my_schedules
is
function odd_even(p_date date default sysdate) return date;
end;
</code>
<code>
CREATE OR REPLACE package body my_schedules  
is

-- even - 30 seconds
-- odd - 1 minute;
function odd_even(p_date date default sysdate) 
return date
is
l_ret date;
l_sec_in_day number := 60*60*24;
begin

case mod( (to_number(to_char(sysdate,'MI'))) ,2)
when 0 then 
--- even return 30 seconds
l_ret:= SYSDATE + 30/l_sec_in_day;
else 
-- odd return a minute
l_ret:= SYSDATE + 60/l_sec_in_day;
end case;
return l_ret;
end;`enter code here`

end;
/

repeat_interval = my_schedules.odd_even :

declare
  l_action varchar2(2000);
  l_repeat_interval varchar2(250) := 'my_schedules.odd_even';
  l_job_name varchar2(30) := 'TESTING_PLSSQL_SCH';
  begin  
    l_action := 'declare dummy number; begin dummy := 1; end;';

    dbms_scheduler.create_job(job_name        => '"'|| l_job_name||'"',
                              job_type        => 'plsql_block',
                              job_action      => l_action,
                              start_date      => sysdate,
                              repeat_interval => l_repeat_interval,
                              comments        => 'just a test'
                              );

    dbms_scheduler.enable(name => '"'||l_job_name||'"');                              
 end; 

:

select job_name, actual_start_date  from DBA_SCHEDULER_JOB_RUN_DETAILS rd where job_name = 'TESTING_PLSSQL_SCH' order by actual_start_date;

job_name |  actual_start_date
--------------------------
TESTING_PLSSQL_SCH  2016/07/14/ 17:33:36,671977 +03:00
TESTING_PLSSQL_SCH  2016/07/14/ 17:34:36,007573 +03:00
TESTING_PLSSQL_SCH  2016/07/14/ 17:35:06,006206 +03:00
TESTING_PLSSQL_SCH  2016/07/14/ 17:36:06,001652 +03:00
TESTING_PLSSQL_SCH  2016/07/14/ 17:36:36,005513 +03:00
TESTING_PLSSQL_SCH  2016/07/14/ 17:37:06,003572 +03:00
TESTING_PLSSQL_SCH  2016/07/14/ 17:38:06,011409 +03:00
TESTING_PLSSQL_SCH  2016/07/14/ 17:38:36,011411 +03:00
TESTING_PLSSQL_SCH  2016/07/14/ 17:39:06,011357 +03:00
TESTING_PLSSQL_SCH  2016/07/14/ 17:40:06,002623 +03:00

Oracle Database Online Documentation 11g Release 1 (11.1)/ / :

+2

All Articles