Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Ordering a list based on letters and numbers

Roxy rollersApr 5 2019 — edited Apr 5 2019

Good morning/evening folks! I looked for something like this online but somehow, what I need is not something I can find on here. Hence I decided to post this. I am almost there but not quite. Here it goes.

with t as (

  select NULL quest from dual

  union

  select 'A1.' from dual UNION

  select 'A2.' from dual UNION

  select 'A3.' from dual UNION

  select 'A4.' from dual UNION

  select 'A5.' from dual UNION

  select 'A5a.' from dual UNION

  select 'A5b.' from dual UNION

  select 'A5c.' from dual UNION

  select 'A5d.' from dual UNION

  select 'A5e.' from dual UNION

  select 'A10.' from dual UNION

  select 'A11.' from dual UNION

  select 'A12.' from dual

)

select * from t

order by regexp_substr(quest, '^\D*') nulls first, to_number(regexp_substr(quest, '\d+'));

My output looks good at first glance but as you can see, the order for Question A5 and it's associates are quite off. Any help in this regard is greatly appreciated.

A1.

A2.

A3.

A4.

A5b.

A5e.

A5d.

A5.

A5a.

A5c.

A10.

A11.

A12.

Thanks

Comments
Post Details
Added on Apr 5 2019
3 comments
1,095 views