I need to join against a dynamic list of numbers that I retrieve from my program dynamically. The number of rows is not fixed, nor are the numbers that are used.
I am not finding a better way to accomplish this than with the following (for my purposes, a temporary table is not helpful):
select 111 as col1, 322 as col2 from dual
union all
select 3 as col1, 14 as col2 from dual
union all
select 56 as col1, 676 as col2 from dual;
Is there a better way to do this? I see that there is a connect by statement that can return multiple rows, but I'm not seeing a way to do multiple rows and columns.
You can use the
CONNECT BYhere with a little math:That will give you your example of three rows. Adjust the
LEVEL <= ...value to get more rows.Update 2022: I see that the OP edited the question the day after my answer, making it invalid.
B. Khan's answer a year later is more on point, though honestly I prefer
CASEoverDECODE--DECODEis more compact but IMOCASEis more readable. I also preferLEVELoverROWNUMhere becauseROWNUMdoesn't always work the way one would expect.