Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Determine if a column exists...

Re: Determine if a column exists...

From: DA Morgan <damorgan_at_psoug.org>
Date: Thu, 06 Jul 2006 14:42:26 -0700
Message-ID: <1152222148.279692@bubbleator.drizzle.com>


Anthony wrote:

> I believe this will fail in general as the rename statement will fail
> if the column does not exist. I guess you the solution is to check if
> column exists then construct a dynamic sql statement and then rename
> it.
> 
> Banavara wrote:

>> You can do a select from all_tab_columns to check if it returns any row
>> for a given table name & column name
>>
>> -rbanavara
>>
>> dogonli..._at_hotmail.com wrote:
>>> Hello,
>>>
>>> Is there a SQL command in ORACLE (10g) that checks if a table column
>>> exists?
>>>
>>> I have over 700 tables of which some have columns that I want to
>>> rename, and some
>>> of the tables don't have the same columns.
>>>
>>> I have a script to do this but it fails if a table doesn't contain the
>>> column I'm
>>> trying to alter (ORA-00904). I would like to check if the column
>>> exists before
>>> executing the alter statement so the script won't abort.
>>>
>>> Something like:
>>> IF EXISTS(tablename.column_name)
>>> ALTER TABLE tablename RENAME COLUMN column_name TO
>>> new_column_name
>>>
>>> Thanks
>>>
>>> Jerry
  1. Don't top post.
  2. A SELECT COUNT(*) FROM all_tab_columns will not fail. -- Daniel A. Morgan University of Washington damorgan_at_x.washington.edu (replace x with u to respond) Puget Sound Oracle Users Group www.psoug.org
Received on Thu Jul 06 2006 - 16:42:26 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US