Oracle Faq (How to change the column name and order of tables in Oracle) _php tutorial

Source: Internet
Author: User
If you want to reprint, please specify the source!
People who have used Oracle know that it's a trivial matter to change the column names and order of tables in Oracle, and 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= ' ID ';

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 names and order of the columns in the SCOTT.T1 table, and if you just want to change the order and don't want to change the column name, just update it again, and the reason you can't do it all at once is because Col#,name is unique in sys.col$.

While this approach has some risks, it is obvious for particularly large table effects, and a general approach will require more storage space, rollback segments, and time overhead.

http://www.bkjia.com/PHPjc/314199.html www.bkjia.com true http://www.bkjia.com/PHPjc/314199.html techarticle if you want to reprint, please specify the source! People who have used Oracle know that it's a trivial matter to change the column names and order of tables in Oracle, and here's a simple way to do it. ...

  • 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.