Pregunta

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
¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top