oracle學習筆記 調整字段順序

2021-10-07 19:29:42 字數 1305 閱讀 7824

oracle修改表字段順序三種方式:

1、重建表

--備份目標表資料:

create table table_temp_name as select * from table_name;

--刪除目標表

drop table table_name;

--按照目標順序重建表

create table table_name (column1,column2,...);

--還原資料

insert into table_name select column1,column2(新順序) from table_temp_name;

2、修改sys的資料字典

--查出表所對應的object_id

--dba使用者使用

select object_id from all_objects where owner='owner_name' and object_name='table_name';

--表歸屬使用者可以使用

select object_id from obj where object_name='table_name';

--通過id查出該錶所有欄位的順序

select obj#,col#,name from sys.col$ where obj#=object_id order by col#;

--更新sys.col$的col#列的值,需要有dba許可權

update sys.col$ set col#=new_place_num where obj#=object_id and name='column_name';

--需要調整所有受影響的列的col#的值

--提交事務

commit;

--需重啟oracle服務,才能生效。

3、通過修改列屬性來實現,此功能12c才支援

--將涉及調整順序的字段列的屬性修改為invisible

alter table  table_name  modify( column1 invisible, column2 invisible, column3 invisible);

--此時通過第2種方式中的方式查詢標誌字段順序,可以看出已經修改為invisible的列的col#列的值為空了,desc table_name也看不到修改為invisible的列了

--按照新的順序將表字段的列更新為visible

alter table  table_name  modify( column3 visible, column2 visible, column1 visible);

--此時再檢視表字段的順序已經調整好了

oracle資料庫調整字段順序

一 以sys身份登入 以dos視窗為基礎 sqlplus as sysdba二 查詢需要修改表的id。select object id from all objects where owner scott and object name emp 注意 owner 是該錶的位置,在scott下面,注意...

mysql 新增字段 刪除字段 調整字段順序

用過mysql的朋友,可能都在使用phpmyadmin 我從2003年開始使用,感覺那東西適合遠端mysql管理,並 不適合單機 單資料庫的管理操作,特別是開發使用。給家推薦乙個軟體管理mysql資料庫 sqlyog 翻譯此頁 manage,monitor mysql servers using o...

oracle調整字段精度的四種方法

oracle調整字段精度的四種方法 01 執行使用者 ddl dml 表名 注釋 建表 授權 同義詞 調整方式一 精度只能調大不能調小 alter table table name a modify column axx number 27,15 調整方式二 借用乙個新的列調整 alter tabl...