0

I have Version_ref_no column having values like

    4.0.0.4
    4.0.0.2
    4.0.0.1
    4.0.0.8
    4.0.0.14 
    4.0.0.23 
    4.0.1.0

Is there any way in Oracle to sort it so that OP should be

   4.0.1.0
   4.0.0.23
   4.0.0.14
   4.0.0.8 
   4.0.0.4 
   4.0.0.2 
   4.0.0.1
user530158
  • 333
  • 7
  • 18
  • 1
    You'll have to 1) splitt the string along the delimiter '.', 2) convert the parts to number and 3) sort on the separated number columns. If the number of substrings is constant, this is a nice homework;) – Marmite Bomber Feb 23 '18 at 10:47

1 Answers1

1
 SELECT * FROM YOUR_TABLE
 ORDER BY 
 to_number(regexp_substr(COL1, '[^.]+', 1, 1)) DESC NULLS FIRST,
 to_number(regexp_substr(COL1, '[^.]+', 1, 2)) DESC NULLS FIRST ,
 to_number(regexp_substr(COL1, '[^.]+', 1, 3)) DESC NULLS FIRST ,
 to_number(regexp_substr(COL1, '[^.]+', 1, 4)) DESC NULLS FIRST ;
venkatesh
  • 151
  • 13