1

Problem

I have searched online for this but can't seem to find a way to do it. I'm by no means an Oracle expert as I've only been working with it for around a month. Is it possible, and if so, how can I get the name of a column that contains XYZ in Oracle?

Please see the below example to better explain what I mean.

Example

I run a query such as:

SELECT * FROM Customers WHERE CustomerNo = 1;

I see results such as:

COLUMN1  COLUMN2  COLUMN3  COLUMN4  COLUMN5
A001     Y        N        10.10    Y

I'm having trouble explain this (I've re-written this 2 or 3 times already) so apologies in advance if it makes no sense to you, but what I am looking for is for example:

SELECT column_name FROM Customers WHERE CustomerNo = 1 AND any_column = Y;

Resulting in:

COLUMN2
COLUMN5
1
  • I would say this is an indication that your database model doesn't fit your domain needs. May 14, 2014 at 17:34

1 Answer 1

1

There is no way to do a * with a comparison in Oracle (or really in any other database). You can, however, use in to facilitate the comparisons:

SELECT column_name
FROM Customers
WHERE CustomerNo = 1 AND 'Y' in (column2, column3, column5);

You can get the list of columns in a table from a system view such as all_tab_columns, if you don't want to type them out individually.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.