あなたが個々の要素を抽出するためにregexp_substr
機能を使用することができ、データベーステーブル内のcronの構文を使用したいですスケジュールタプルから。たとえばregexp_substr(schedule, '[0-9*]+', 1,1)
は分要素を抽出し、regexp_substr(sched, '[0-9*]+', 1, 2)
は時間要素を抽出します。 4番目のパラメータは、目的の要素を選択します。 EXTRACT
またはTO_CHAR
関数を使用して、タイムスタンプのさまざまな部分を比較して比較することができます。
with cron(ID, Sched) as (
select 102, '00 9 * * * *' from dual
), exec(id, ts) as (
select 102, to_timestamp('2017-11-05 9:00:00', 'yyyy-mm-dd hh24:mi:ss') from dual union all
select 102, to_timestamp('2017-11-05 9:05:00', 'yyyy-mm-dd hh24:mi:ss') from dual
), c2 as (
select id
, sched
, regexp_substr(sched,'[0-9*]+',1,1) min
, regexp_substr(sched,'[0-9*]+',1,2) hour
, regexp_substr(sched,'[0-9*]+',1,3) day
, regexp_substr(sched,'[0-9*]+',1,4) mon
, regexp_substr(sched,'[0-9*]+',1,5) wday
, regexp_substr(sched,'[0-9*]+',1,6) year
from cron
)
select c2.*
, exec.ts
, case when (year = '*' or to_number(to_char(ts,'yyyy')) = to_number(year))
and (mon = '*' or to_number(to_char(ts,'mm') ) = to_number(mon))
and (day = '*' or to_number(to_char(ts,'dd') ) = to_number(day))
and (hour = '*' or to_number(to_char(ts,'hh24')) = to_number(hour))
and (min = '*' or to_number(to_char(ts,'mi') ) = to_number(min))
and (wday = '*' or to_number(to_char(ts,'d') ) = to_number(wday))
then 'OK'
else 'KO'
end Match
from exec
join c2
on c2.id = exec.id;
必要な結果を得るために必要に応じて、case文の論理式を部分的または全体的に移動します。
どのデータベースを使用していますか? – Sentinel
@センチネル:Oracleを使用しています – Giova