Reputation: 13
I have a requirement where I want to rename a column. In in this case, it should happen like:
1.) I need to create a new column with the existing column structure. 2.) Migrate the data to the new column. 3.) Retain the old column.
I don't have the new column structure and I have to take it from the old column.
TIA.
Upvotes: 0
Views: 737
Reputation: 838096
You don't need to select into the same table. Perform the following steps:
Upvotes: 4
Reputation: 332541
What version of Oracle? You can rename the column since 9i R2:
ALTER TABLE your_table
RENAME COLUMN old_name to new_name;
If you're set on recreating the table so you can use SELECT INTO
, then you'd want to use the following steps:
Lock the original table:
LOCK TABLE old_table IN EXCLUSIVE MODE;
Rename the table:
RENAME old_table TO old_table_orig
Create the new table with the correct/updated columns
SELECT INTO
script(s) to populate the new table, handling data type changes if there are anyUpvotes: 1