Oracle SQL to Sort Version Numbers

后端 未结 3 1097
有刺的猬
有刺的猬 2021-01-03 09:06

In Oracle, just using the ORDER BY does not sort version numbers. My Version_Number field is declared as a VARCHAR and I cannot change

3条回答
  •  孤街浪徒
    2021-01-03 09:55

    This is one way to do it. First order by the number before . and then by the numbers after .

    select version_number 
    from mytable 
    order by substr(version_number, 1, instr(version_number,'.')-1) desc
            ,length(substr(version_number, instr(version_number,'.')+1)) desc
            ,substr(version_number, instr(version_number,'.')+1) desc
    

提交回复
热议问题