简体   繁体   中英

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. Currently, after 5 unsuccessful attempts to upload the file, the batch will mark the record as failed and send a notification email. I'm trying to enhance this batch to try upload 2 more times with 6 hours gap after the 5 attempts. ie, till the FAIL_CTR reaches 5, record will be tried to upload every 5 mins. Once the FAIL_CTR reaches 5, record will be tried to upload every 6 hours.

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. I just need it to be done once after 6 hours after the 5th try and once after 6 hours after the 6th try. 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. I assume that a retry reliably updates the last attempted date and increments the fail counter..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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