------解决方案-------------------- 1、decode方式
order by decode(col1,'1001',1,'1008',2,'1002',3,'1010',4,col1)
2、instr方式
order by instr('1001,1008,1002,1010',col1) ------解决方案-------------------- 很有趣的问题,这其实是个树形排序。楼主可以重点看看level的用法。
Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.2.0
Connected as OKMDB
SQL> SELECT * FROM idtest;
A B
---------- ----------
1001 1008
1002 1010
1008 1002
1010 1003
SQL> SELECT A, B FROM idtest t START WITH t.a = 1001 CONNECT BY PRIOR t.b = t.a;
A B
---------- ----------
1001 1008
1008 1002
1002 1010
1010 1003