Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2005
    Posts
    220

    Unanswered: Sort a varchar numerically

    Does anyone know how to sort the following list numerically?

    2
    4
    1
    8
    11a
    4a

    giving:

    1
    2
    4
    4a
    8
    11

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    Code:
    $ sort -n -o abc.srt abc.raw
    $ cat abc.raw
    2
    4
    1
    8
    11a
    4a
    $ cat abc.srt
    1
    2
    4
    4a
    8
    11a
    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
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    LOL! Excellent!

    Here's one with the regular expressions:
    Code:
    SQL> SELECT col
      2  FROM TEST
      3  ORDER BY TO_NUMBER(REGEXP_REPLACE(col, '[[:alpha:]]', '')),
      4           REGEXP_REPLACE(col, '[[:digit:]]', '')
      5           NULLS FIRST;
    
    COL
    ----------
    1
    2
    4
    4a
    8
    11c

Posting Permissions

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