sql - How to sort a varchar in oracle -


this question has answer here:

select cm.* employee cm  order cm.row_id 

the row_id varchar type , want retrive sorting order follows

in above query row_id varchar2 in database, , want retrive values integer.

i have tried order to_number(cm.row_id) giving error invalid number

edit:-

my sample data is:-

1 1.1 1.5 1.6 2.5 2.6 1.7 1.8 1.9 1.10 1.11 1.12 1.2 1.1.1 1.3 1.4 1.1.1.1 1.13 2 2.1 2.2 2.3 2.4 1.16 1.14 1.15 1.17 

i want retrive like:-

1 1.1 1.1.1 1.1.1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 1.10 1.11 1.12 1.13 1.14 1.15 1.16 1.17 2 2.1 2.2 2.3 2.4 2.5 2.6 

@murali can try this

create table tt (sno varchar2(10)); insert tt values('1'); insert tt values('1.1.1'); insert tt values('1.1.1.2'); insert tt values('1.1'); insert tt values('1.2'); insert tt values('1.3'); insert tt values('1.4'); insert tt values('1.5'); insert tt values('1.6'); insert tt values('1.7'); insert tt values('1.8'); insert tt values('1.9'); insert tt values('1.10'); insert tt values('1.11'); insert tt values('1.12'); insert tt values('1.13'); insert tt values('1.14'); ----insert tt values('1.15'); insert tt values('2'); insert tt values('2.1'); insert tt values('2.2'); insert tt values('2.3'); insert tt values('2.4');  insert tt values('1.16'); 

then:

select sno tt order     to_number(regexp_substr(sno, '[[:digit:]]+')),     to_number(regexp_substr(sno, '[[:digit:]]+', 1, 2)) nulls first,     to_number(regexp_substr(sno, '[[:digit:]]+', 1, 3)) nulls first 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -