• info@robertoaiello.net

Trick & tips : Change position columns in Oracle database

Trick & tips : Change position columns in Oracle database

If you want add new columns in a table of oracle database and set it in a specific position, you can use this sql command:

RENAME your_table_name TO your_table_name_old;

CREATE TABLE your_table_name AS SELECT

………………………………………….

FROM your_table_name_old;

DROP TABLE your_table_name_old;

Example:

If You have TABLE called TAB_A with columns called A,B,C. If you add a column called D between B and C (new sequence is: A,B,D,C) :

First add column D in TAB_A :

ALTER TABLE TAB_A

ADD D date;

Next, your command will be:

RENAME TAB_A TO TAB_A_old;

CREATE TABLE TAB_A AS SELECT

A,B,D,C

FROM TAB_A_old;

DROP TABLE TAB_A_old;

robi.aiello@gmail.com

Leave a Comment