I have a client requirement that requires day wise unique ID. I am working on Oracle 12c.
In that case the table (Client_Doc) structures as follows:
Doc_ID (PK), Date(PK), Doc_Description, Other_Columns
Sample Data Be like:
Value_Date Doc_ID Doc_Description
01-11-2020 1 Test Doc
01-11-2020 2 User Info
01-11-2020 3 Customer Doc
02-11-2020 1 Live
02-11-2020 2 Region
03-11-2020 1 Test
So if I want to generate ID I can do:
SELECT NVL(MAX(Doc_ID), 0) + 1
INTO V_ID
FROM Client_Doc
WHERE Value_Date = :P_DATE;
But it is not a good practice due to dirty read and performance issue for a large quantity of table rows and also can't use the sequences because of the requirement. What will be the best approach to meet up the requirement?