Oracle Faq (How to change the column names and order of tables in Oracle)

Source: Internet
Author: User
Tags commit sql
If you want to reprint Oracle, please specify the source!
As anyone who has ever used Oracle knows, to change the column names and order of tables in Oracle is a trivial matter, here's a simple way to do it.

Sql> Select object_id from all_objects where owner= ' SCOTT ' and object_name= ' T1 ';

object_id
----------
6067
Sql> Select Obj#,col#,name from sys.col$ where obj#=6067;

obj# col#
---------- ----------
NAME
------------------------------------------------------------
6067 1
Id

6067 2
NAME

sql> Update sys.col$ set name= ' new_id ', col#=3 where obj#=6067 and name= ' IDs ';

1 row updated.

sql> Update sys.col$ set name= ' My_name ', col#=1 where obj#=6067 and name= ' name ';

1 row updated.

sql> Update sys.col$ set col#=2 where obj#=6067 and col#=3;

1 row updated.

Sql> commit;

Commit complete.

Sql> select * from Scott.t1;

ID NAME
---------- --------------------
3 Cheng
2 Yong
1 Xin
2 Gototop
1 Topcio
2 Yongxin
1 cyx

7 rows selected.
sql> shutdown Immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
Sql> Startup
ORACLE instance started.

Total System Global area 128159368 bytes
Fixed Size 732808 bytes
Variable Size 117440512 bytes
Database buffers 8388608 bytes
Redo buffers 1597440 bytes
Database mounted.
Database opened.
Sql> select * from Scott.t1;

My_name new_id
-------------------- ----------
Cheng 3
Yong 2
Xin 1
Gototop 2
Topcio 1
Yongxin 2
Cyx 1

7 rows selected.

So far we've given the column names and orders in the Scott.t1 table, and if you just want to change the order and not change the name of the column, just update it and you can't do it all at once because sys.col$ Col#,name are unique.

Although this method has a certain risk, but for particularly large table effect is very obvious, and the general method will require more storage space, rollback segment and time overhead.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.