I need to know what the best practice is regarding running a query periodically on Oracle (I'm using 11g).
In my particular use case I have a DUE_DATE
specified in table x
. What I want to do is to run a query at 00:01 every day to calculate the status (OK, Warn, Critical or Overdue) of some records. The status of a particular record is calculated from today's date (where 'today' is the day the query is being run) relative to x.DUE_DATE
and some user-specified values for what signifies 'warn' and 'critical' (contained within table y
).
- OK -->
today < x.DUE_DATE - y.WARN
- Warn -->
today >= x.DUE_DATE - y.WARN and today < x.DUE_DATE - y.CRITICAL
- Critical -->
today >= x.DUE_DATE - y.CRITICAL and today <= x.DUE_DATE
- Overdue -->
today > x.DUE_DATE
What is the best way of running this query periodically? I have found the following options but am not sure which is best for my use case:
I know that I could just calculate the status dynamically upon every user request but as stauses only change once a day I thought it would be more efficient to do the calculation and cache the subsequent result once a day too.
Many thanks in advance.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…