Search code examples
sqlstringoraclemaxrecursive-query

Oracle SQL Find max digit in number in cell


I have a column like that :

enter image description here

How can I find the max digit column? ( I want to select the max digit from the left column and write it to a new column)

WITH ORACLE SQL

THANKS!!!


Solution

  • Solving it like a pro:

    Creating sample data:

    CREATE TABLE tab as
    WITH t(col) AS
    (
     SELECT 134425  FROM dual UNION ALL
     SELECT 6453356 FROM dual UNION ALL
     SELECT 65267   FROM dual UNION ALL
     SELECT 9999    FROM dual UNION ALL
     SELECT 467533  FROM dual
    )
    SELECT * FROM t;
    

    Solution:

    select * from tab,
    lateral
    ( 
        select max(substr(col, level, 1)) max_digit
        from   dual
        connect by level <= length(col)
    )
    

    Output:

    enter image description here