Create an Oracle sequence for each day of the week i.e.
CREATE SEQUENCE SEQ_MON
START WITH 1
INCREMENT BY 1
ORDER;
CREATE SEQUENCE SEQ_TUE
START WITH 1
INCREMENT BY 1
ORDER;
ETC up to SEQ_SUN
Create an Oracle Stored Procedure that returns:
1. a datetime
2. a sequence number for the day of the week corresponding to above datetime
Logic as per below:
- Store current date and time in a variable
- Get day of week corresponding to date in variable.
Note: Use a formula that is independent of NLS_TERRITORY setting. You could use: 1 + TRUNC (DT) - TRUNC (DT, 'IW') to get 1 for Mon.
- Get next sequence from sequence corresponding to above day of the week
- Return the datetime in the variable and the new sequence number obtained above.
Schedule Job:
Create a scheduled job that runs at 1 a.m. (not midnight) every day to reset seq of previous day.
With the above approach, you are safe with 24X7 operations.
IMPORTANT:
The datetime returned should be used to timestamp your incoming request so that the timestamp of your request shall match the sequence number allotted to it. This is important for requests hitting just before midnight.