Base 36 to Base 10 conversion using SQL only

后端 未结 2 1226
南旧
南旧 2020-12-01 11:08

A situation has arisen where I need to perform a base 36 to base 10 conversion, in the context of a SQL statement. There doesn\'t appear to be anything built into Oracle 9

2条回答
  •  感动是毒
    2020-12-01 11:49

    select sum(position_value) from
    (
      select power(36,position-1) * case when digit between '0' and '9' 
                                         then to_number(digit)
                                         else 10 + ascii(digit) - ascii('A')
                                    end
              as position_value
        from (
              select substr(input_string,length(input_string)+1-level,1) digit, 
                     level position
                from (select '01Z' input_string from dual)
                connect by level <= length(input_string)
             )
    )
    

提交回复
热议问题