SELECT
`cron` as `执行周期规则`,
concat(
if(
locate('/',SUBSTRING_INDEX(SUBSTRING_INDEX(`cron`, ' ', 5), ' ', -1))>0,
concat('每',replace(SUBSTRING_INDEX(SUBSTRING_INDEX(`cron`, ' ', 5), ' ', -1),'*/',''),'月'),
if(SUBSTRING_INDEX(SUBSTRING_INDEX(`cron`, ' ', 5), ' ', -1)='*','',concat(SUBSTRING_INDEX(SUBSTRING_INDEX(`cron`, ' ', 5), ' ', -1),'月'))
),
if(
locate('/',SUBSTRING_INDEX(SUBSTRING_INDEX(`cron`, ' ', 4), ' ', -1))>0,
concat('每',replace(SUBSTRING_INDEX(SUBSTRING_INDEX(`cron`, ' ', 4), ' ', -1),'*/',''),'天'),
if(SUBSTRING_INDEX(SUBSTRING_INDEX(`cron`, ' ', 4), ' ', -1)='*','每天',concat(SUBSTRING_INDEX(SUBSTRING_INDEX(`cron`, ' ', 4), ' ', -1),'日'))
),
if(
locate('/',SUBSTRING_INDEX(SUBSTRING_INDEX(`cron`, ' ', 3), ' ', -1))>0,
concat('每',replace(SUBSTRING_INDEX(SUBSTRING_INDEX(`cron`, ' ', 3), ' ', -1),'*/',''),'小时'),
if(SUBSTRING_INDEX(SUBSTRING_INDEX(`cron`, ' ', 3), ' ', -1)='*'||SUBSTRING_INDEX(SUBSTRING_INDEX(`cron`, ' ', 3), ' ', -1)='0','',concat(SUBSTRING_INDEX(SUBSTRING_INDEX(`cron`, ' ', 3), ' ', -1),'时'))
),
if(
locate('/',SUBSTRING_INDEX(SUBSTRING_INDEX(`cron`, ' ', 2), ' ', -1))>0,
concat('每',replace(SUBSTRING_INDEX(SUBSTRING_INDEX(`cron`, ' ', 2), ' ', -1),'*/',''),'分钟'),
if(SUBSTRING_INDEX(SUBSTRING_INDEX(`cron`, ' ', 2), ' ', -1)='*'||SUBSTRING_INDEX(SUBSTRING_INDEX(`cron`, ' ', 2), ' ', -1)='0','',concat(SUBSTRING_INDEX(SUBSTRING_INDEX(`cron`, ' ', 2), ' ', -1),'分钟'))
),
if(
locate('/',SUBSTRING_INDEX(`cron`, ' ', 1))>0,
concat('每',replace(SUBSTRING_INDEX(`cron`, ' ', 1),'*/',''),'秒'),
if(SUBSTRING_INDEX(`cron`, ' ', 1)='*'||SUBSTRING_INDEX(`cron`, ' ', 1)='0'||SUBSTRING_INDEX(`cron`, ' ', 1)='00','',concat(SUBSTRING_INDEX(`cron`, ' ', 1),'秒'))
)
)as `频率`
-- concat(SUBSTRING_INDEX(`cron`, ' ', 1),'秒') AS seconds,
-- SUBSTRING_INDEX(SUBSTRING_INDEX(`cron`, ' ', 2), ' ', -1) AS minutes,
-- SUBSTRING_INDEX(SUBSTRING_INDEX(`cron`, ' ', 3), ' ', -1) AS hours,
-- SUBSTRING_INDEX(SUBSTRING_INDEX(`cron`, ' ', 4), ' ', -1) AS day_of_month,
-- SUBSTRING_INDEX(SUBSTRING_INDEX(`cron`, ' ', 5), ' ', -1) AS month,
-- SUBSTRING_INDEX(`cron`, ' ', -1) AS day_of_week,
FROM
(
(select "0 3 * * *" as cron)
union all
(select "0 */4 * * *" as cron)
union all
(select "11 17 1 * *" as cron)
union all
(select "11 9,11,13 2 * *" as cron)
union all
(select "01 9 * * *" as cron)
union all
(select "01 9 * * *" as cron)
) a
用mysql解析crontab表达式
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...