简体   繁体   English

使用mod运算符的Oracle查询

[英]Oracle query using mod operator

I have a spring batch which tries to upload pending documents to a server every 5 mins from the below table. 我有一个春季批处理,尝试从下表中每5分钟将待处理的文档上载到服务器。 Currently, after 5 unsuccessful attempts to upload the file, the batch will mark the record as failed and send a notification email. 当前,在5次未成功上传文件的尝试之后,该批处理会将记录标记为失败并发送通知电子邮件。 I'm trying to enhance this batch to try upload 2 more times with 6 hours gap after the 5 attempts. 我正在尝试增强此批处理,以尝试在5次尝试之后有6小时的间隔再上传2次。 ie, till the FAIL_CTR reaches 5, record will be tried to upload every 5 mins. 也就是说,直到FAIL_CTR达到5时,才会尝试每5分钟上传一次记录。 Once the FAIL_CTR reaches 5, record will be tried to upload every 6 hours. FAIL_CTR达到5后,将尝试每6小时上传一次记录。

Here is what I have tried so far for the query which selects eligible records for the batch to upload. 到目前为止,这是我为查询选择的要上传的批处理记录的内容。 The issue is that, for a record which already failed 5 times, on the 6th hour, the batch will try to upload in every 5 mins. 问题是,对于已失败5次的记录,在第6小时,批次将尝试每5分钟上传一次。 I just need it to be done once after 6 hours after the 5th try and once after 6 hours after the 6th try. 我只需要在第5次尝试后6小时后和第6次尝试后6小时后再执行一次即可。 How can I achieve it ? 我该如何实现?

select * from SUPPORT_DOCS DOCS   
        where (DOCS.FAIL_CTR < 5  OR (DOCS.FAIL_CTR < 7 AND floor(mod(24*(SYSDATE-DOCS.LAST_ATTEMPTED_DATE),6))=0))
        and DOCS.STATUS='F';

表

I think the logic would be 我认为逻辑是

 Select * from SUPPORT_DOCS DOCS   
    where (
      (DOCS.FAIL_CTR < 5  OR 
      (DOCS.FAIL_CTR = 5 AND SYSDATE-DOCS.LAST_ATTEMPTED_DATE > 0.25) OR 
      (DOCS.FAIL_CTR = 6 AND SYSDATE-DOCS.LAST_ATTEMPTED_DATE > 0.5)
    )
    and DOCS.STATUS='F';

date1 - date2 in oracle produces a result in days, so you want quarter of a day delay before a retry, then half a day. oracle中的date1-date2以天为单位生成结果,因此您要在重试之前延迟四分之一天,然后再延迟半天。 I assume that a retry reliably updates the last attempted date and increments the fail counter.. 我假设重试会可靠地更新上一次尝试的日期并增加失败计数器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM