有一個哥們提出一個問題:
有個表,創建時候的列順序是a,b,c
如何使用select * 的時候,讓列的顯示順序是a,c,b 而且任性地必須使用select *來查詢,且不能重建表。
假設有個表test
SQL> select * from test; A B C -------------------- -------------------- -------------------- you pig are SQL> select a,c,b from test; A C B -------------------- -------------------- -------------------- you are pig SQL>
按照其要求,應該是以下顯示方式:
SQL> select * from test; A C B -------------------- -------------------- -------------------- you are pig SQL>
可以通過修改sys.col$表來改變表中列的順序
SQL> SELECT owner,object_name,object_id FROM ALL_OBJECTS WHERE OBJECT_NAME='TEST';
OWNER OBJECT_NAME OBJECT_ID
------------------------------ ------------------------------ ----------
SYS TEST 88842
SQL> select obj#,col#,name from sys.col$ where obj# =88842 order by col#;
OBJ# COL# NAME
---------- ---------- ------------------------------
88842 1 A
88842 2 B
88842 3 C
SQL> update sys.col$ set col#=2 where obj# =88842 and name='C';
1 row updated.
SQL> update sys.col$ set col#=3 where obj# =88842 and name='B';
1 row updated.
SQL> commit;
Commit complete.
SQL> select * from test;
A C B
-------------------- -------------------- --------------------
you are pig
SQL>
