Skip to content
Advertisement

Oracle: SELECT value from where clause as dummy table

after a lot of searching I unfortunately couldn’t find a solution for the following task:

I need an Oracle-SQL-Query that returns the value from the WHERE-clause as the result value. This sounds easy, but I just couldn’t find out how to achieve this.

Example (how it should be):

Desired Result:

I know that I could write something like

But in this case I cannot hard-code the ‘MY_VALUE’, it can only be provided in the WHERE-clause (not in the SELECT or FROM parts or elsewhere).

Is there any way to achieve this in Oracle? Thanks in advance for ideas!

Advertisement

Answer

Here’s a really nasty hack, more for curiosity than anything:

Or without the subquery, if you can make the where clause more complicated:

Either way it’s looking in the data dictionary for the statement that is currently being executed by this session; and I’m not entirely sure that’s a valid thing to do. This seems to work in 11g and 12c, and (so far) always reports the value being searched for, but I don’t know that it is guaranteed. It feels like an abuse of the space-time continuum…

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