Re: Renaming a Column

From: Daniel A. Morgan <Daniel.Morgan_at_attws.com>
Date: Mon, 16 Jul 2001 09:08:17 -0700
Message-ID: <3B531171.79712D98_at_attws.com>


Randall Woodman wrote:

> Sorry for the cross post but I'm desperate for an answer.
>
> Is there a way to rename a column in an existing table? For example,
> suppose I had a table named FOO.
>
> CREATE TABLE FOO (
> FOOWHO VARCHAR2 (12) NOT NULL,
> BARNONE VARCHAR2 (18) NOT NULL,
> FOOBAR VARCHAR2 (8) NOT NULL,
> )
>
> Now suppose I want to rename the column FOOBAR to FUBAR. I know I could do
> the following
> 1. Add a new column called FUBAR
> 2. update the column FUBAR with the data in FOOBAR
> 3. Drop the column FOOBAR
>
> However, I was thinking that there was a way to do this using a single
> ALTER statement. For example,
> alter table <table_name> rename column <column_name> new_column_name
> However, that doesn't work.
>
> I'm running Oracle 8.1.6
>
> Thanks for your help.
>
> -=} Randall {=-

In 8i no. But I'd hardly get desparate. There is no need to rename a column. When you select from the column, in a view or SQL statement just give it an alias.

SELECT field1 NEWNAME
FROM mytable;

retrieves the values in field1 and renames the column to NEWNAME.

Alternatively ... drop the table and recreate it.

Daniel A. Morgan Received on Mon Jul 16 2001 - 18:08:17 CEST

Original text of this message