I run a message-based system in which a sequence of unique integer identifiers will be fully represented at the end of the day, although they will not necessarily arrive in order.
I am looking for help finding missing identifiers in this series using SQL. If the column values ββhave a lower value, how can I find which identifiers I skip in this sequence, in this case 6
?
The sequence starts and ends at an arbitrary point every day, so min and max will be different for each run. Coming from the background of Perl through some regular expression.
ids 1 2 3 5 4 7 9 8 10
Help would be greatly appreciated.
Edit: we run the oracle
Edit2: Thanks everyone. I will work through your decisions next week in the office.
Edit3: I currently dwell on something like below: ORIG_ID is the original id column, and MY_TABLE is the original column. If you take a closer look at my data, there are many cases in the line, except for the number of data. In some cases, there is a prefix or suffix for non-numeric characters. In other cases, dashes or spaces are placed in the numeric identifier. In addition, identifiers periodically appear several times, so I included different ones.
I would appreciate further input, especially regarding the best way to remove non-zero characters.
SELECT CASE WHEN NUMERIC_ID + 1 = NEXT_ID - 1 THEN TO_CHAR( NUMERIC_ID + 1 ) ELSE TO_CHAR( NUMERIC_ID + 1 ) || '-' || TO_CHAR( NEXT_ID - 1 ) END MISSING_SEQUENCES FROM ( SELECT NUMERIC_ID, LEAD (NUMERIC_ID, 1, NULL) OVER ( ORDER BY NUMERIC_ID ASC ) AS NEXT_ID FROM ( SELECT DISTINCT TO_NUMBER( REGEXP_REPLACE(ORIG_ID,'[^[:digit:]]','') ) AS NUMERIC_ID FROM MY_TABLE ) ) WHERE NEXT_ID != NUMERIC_ID + 1
source share