Skip to content
Advertisement

Get range of columns with specific value in Oracle

I wasn’t sure how to title this question, but I’ve got an Oracle table that has a column for each day of the week. These represent the days a business is open. The values in these columns is either ‘Y’ or ‘N’. This is how the table was setup years ago and I am unable to change it.

I need to be able to query this table and get results like the following, but am not sure where to even start.

Is this even possible in a query or will I need to use a function? If a function would make it easier, I’d be fine with that solution as well.

Advertisement

Answer

Found easier solution:

Full example:

Result:

Edit: expanding on the original answer to apply the same process to months of the year. I had to wrap the month number in square brackets in the decode. Then in the regexp_replace, I specified a non-matching list (period and whitespace).

Here’s the full example:

and the results:

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement