Question

Do we have any function in oracle do this scenario.

There are 2 columns in table col1, col2.

col1 either has 'Y' or 'N' or NULL

col2 eitehr has 'Y' or 'N' or NULL 

But always only one of the column has value 'Y'.

So , i want to check first col1 whether it has 'Y' ,if it has i want a string "COL1 found" ,if col2 has 'Y' i want a string "COL2 found". Is it possible with NVL2 and Decode function. With one column ,i can able to do that. But here i have to check 2 columns .Please note that i want a result in single row.

Regards,

Chaitu

Was it helpful?

Solution

select case when col1 = 'Y' then 'Col1 found' when col2 = 'Y' then 'Col2 found' end f
from yourtable

UPD.

select decode (col1, 'Y', 'col1 found', decode(col2, 'Y', 'col2 found')) from yourtable
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top