I have a tough problem I am trying to solve.
I have an Oracle Database table with a number of columns in it.
One of those columns is a Varchar2 column that has what amounts to a 5 digit counter in it (12345).
At the moment, there is a screen that a user enters data into, that relies on retrieving data using those values in the column. Additionally, it uses the knowledge of those values to determine what the next free value is.... in other words, if you were writing a new record, and 11111 was already used, then it would take 11112, and so on.
Now, it is entirely possible for there to be gaps in the numbers in the column... hence I need to know what the next FREE number is given a random start point in the column, and with a ceiling declared as the max available value as well.
Using only an Oracle DB solution, what would be the best way to tackle this?
I have been working on a server side solution... but alas, I feel this is really a job for the database server... not to mention, server side it's really slow. I feel that it really needs to be on the database server.
I would imagine a similar solution to what was devised server side would be used to work this on the DB server; ie starting from record x, increment each record from there by 1 until you either a) find NO record (which is what you want), or b) meet or exceed the ceiling.
I am not an Oracle guy; my background is SQL Server, but my current assignment requires use of Oracle.
I was looking at cursors, functions, packages... but I felt a bit overwhelmed. I felt that using a bulk data cursor was a good place to start, but really didn't know where to go from there.
Am looking for any advice on the best way to approach this scenario.
Thank you for taking the time to read this.
(EDIT) As I revealed in the comments below, the column in question actually contains two different types of numbering systems, base 10 (12345), and base 36 (1234A).
So, a better description of the problem would be,
Given a random starting point, and the max ceiling, solve for
the next FREE number
OR
the last used entry before the next gap begins.
I believe we have one potential answer so far that would work with either case.
Again, thanks everyone for your time.