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 OKMDBSQL> SELECT * FROM idtest; A B ---------- ---------- 1001 1008 1002 1010 1008 1002 1010 1003SQL> 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 1003SQL>
order by decode(col1,'1001',1,'1008',2,'1002',3,'1010',4,col1)
2、instr方式
order by instr('1001,1008,1002,1010',col1)
Connected as OKMDBSQL> SELECT * FROM idtest; A B
---------- ----------
1001 1008
1002 1010
1008 1002
1010 1003SQL> 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 1003SQL>
2楼用的11g吗?11g不是没有sqlplusw这个工具了吗?怎么看着这么像?
是PL/SQL Developer的command windows.