Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2004
    Posts
    58

    Lightbulb Unanswered: Sorting problem on VARCHAR2 column datatype containing numeric data

    I have a column name assessment_number VARCHAR2(10).
    It has the following data in 'desired' order:

    5.2.4
    5.2.5
    5.2.10
    5.10.1
    8.1.2
    8.1.3
    8.1.10
    8.1.30

    But when I do SELECT ... ORDER BY... 10 always comes before 2, 3, etc.

    5.10.1
    5.2.10
    5.2.4
    5.2.5
    8.1.10
    8.1.2
    8.1.3
    8.1.30

    How can I sort the data correctly?

    Thanks in advance!

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    One way is to ZERO fill the "sub.fields"

    02.10.01
    05.01.13
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    May 2004
    Location
    Redwood Shores, CA
    Posts
    68
    Messy but if you got to do it, you got to do it.

    order by
    to_number(substr(assessment_number,1,instr(assessm ent_number,'.',1,1)-1)),
    to_number(substr(assessment_number,instr(assessmen t_number,'.',1,1)+1,instr(assessment_number,'.',1, 2)-1)),
    to_number(substr(assessment_number,instr(assessmen t_number,'.',1,2)+1))

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •