Is there an easy way to get the max number from a String in PL/SQL

19 Views Asked by At

I have a database field that contains a string of numbers like 50,40,60,10,0,4 is there any easy way to determine the highest number in the sting other than iterating thru the string and comparing values?

1

There are 1 best solutions below

0
Bruno Tatsch On

If you guarantor if exists just numbers on field you can use function MAX(TO_NUMBER()).

Example:

SELECT MAX(TO_NUMBER(user_registration)) FROM USER;

If you want to remove the caracteres you can use REGEXP_REPLACE to use just the numbers: REGEXP_REPLACE(seu_campo, '[^0-9]', '').

SELECT MAX(REGEXP_REPLACE(user_registration, '[^0-9]', '')) FROM USER;