I have a table with the following dataset
ID (VARCHAR2 field) D001 D002 D010 D0012
I use max()in this field.
max()
Select max(ID) from <table-name>;
As a result, returns D010.
D010
Why is the result not D0012?
D0012
You get D010it because it D010appears in alphabetical order after D0012or in another way, D01appears after D00, and therefore everything that is D01xcomes after everything that begins with D00x.
D01
D00
D01x
D00x
below code works for me according to your expectation
select max(to_number(regexp_substr(id, '\d+'))) id from <yourtable>;
, , .
select MAX(CAST(REPLACE(REPLACE(ID, 'D', ''), '', '') as int)) from <table-name>
it should work
Select MAX(ID) from table where IsNumeric(ID) = 1 ;