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

Home -> Community -> Usenet -> c.d.o.misc -> Re: Need to determine if a column exists or not

Re: Need to determine if a column exists or not

From: Andrew Triggs <andytriggs_at_yahoo.co.uk>
Date: Thu, 17 Oct 2002 23:48:28 +0100
Message-ID: <3daf3e43$0$5811$fa0fcedb@lovejoy.zen.co.uk>


Query the data dictionary view ALL_TAB_COLUMNS

SELECT 'x'
FROM all_tab_columns
WHERE table_name = <your table>
AND column_name = <column to look for>

Regards, Andy

news.integraonline.com wrote:

> I am in a situation where I need to determine is a column exists in a
> database or not.
>
> Does anyone know a way to do this.
>
>
> If you are asking the "Why would one need to do this!", that I have
> seen in
> response to others ?'s that are like this.
>
> I will explain.
>
> Overview: I have an application that executes scripts using the Oracle
> OLEDB
> provider, the application queries a database, and determines what changes
> need to be made to a customers database. It then executes a SQL script
> based
> on the determination made.
>
> Problem: Somewhere in the past a bad version of a script file was
> distributed to an undetermined amount of customers, this file did NOT
> add a
> column X to the database. So we are left with some customers that DO have
> column X and some that DON'T.
>
> We can't just drop column X for the ones that already have it, because
> they
> have data in the field. And creating temp tables seems like a pain.
>
> Resolution(hopefully): Find a way to do determine if the column
> exists... If
> it does not we need to add it.
> Example (not intended to be Oracle Syntax),
> If ColumnX.Exists Then
> Alter table TableName Add X
> End If
>
> If we can do this, everyone is happy. And we don't have some customers
> with,
> and some without.
>
>
Received on Thu Oct 17 2002 - 17:48:28 CDT

Original text of this message

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