![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hello, for some reason I need something like a "select 123 as abc from dual;" but with several result rows rather than one. The result should look like ABC 123 456 789 So I came up with the following solution which seems akward to me: SELECT abc FROM (SELECT level abc FROM dual CONNECT BY level <= 999 ) WHERE abc IN(123, 456, 789) ; It was essential to me that I could easyly change the number of results like here through just writing them between the brackets, otherwise I could have used a UNION statement. But my solution looks ugly, especially the "<=999" because I will need it for bigger than 3 digit numbers. Does anybody know a better solution? Thanks and best, Hans |
#3
| |||
| |||
|
#4
| |||
| |||
|
|
Hi Maxim, Thanks. This is an elegant solution. However I wonder if there is a possibility which does not involve creating anything, just a plain "one sql statement solution" ... Best, Hans |
#5
| |||
| |||
|
|
does this count as a one sql statement solution? select 123 as abc from dual union select 456 from dual union select 789 from dual; |
#6
| |||
| |||
|
|
Hi Joel! does this count as a one sql statement solution? select 123 as abc from dual union select 456 from dual union select 789 from dual; I explicitly stated that I know that union could have been used and that I was looking for a solution that is easy to adapt from 1 to n rows. Don't misunderstand me, at this point I am not looking for "a" solution anymore, both my method and Maxim's solution work fine and yours would work, too, though it is less flexible. I just would like to learn more about sophisticated solutions regarding my problem to let me understand (Oracle) SQL better. Best, Hans |
#7
| |||
| |||
|
|
On Feb 13, 8:45 am, Hans Mayr <mayr1... (AT) gmx (DOT) de> wrote: Hi Joel! does this count as a one sql statement solution? select 123 as abc from dual union select 456 from dual union select 789 from dual; I explicitly stated that I know that union could have been used and that I was looking for a solution that is easy to adapt from 1 to n rows. Don't misunderstand me, at this point I am not looking for "a" solution anymore, both my method and Maxim's solution work fine and yours would work, too, though it is less flexible. I just would like to learn more about sophisticated solutions regarding my problem to let me understand (Oracle) SQL better. Best, Hans A global temporary table might be a solution for you. You would define the definition once then each program that referenced the table could execute a procedure or chunk of code to insert the values to be used in this run. Then subsequent SQL statements could reference the GTT to get the values. Because each session gets its own copy of the GTT multiple processes could run concurrently with different sets of values. If the application is web based then you might have to use a permanent table of tables structure where you add an identifier that the end user session uses to identify its list of values. The best solution depends on exactly why you need the list, how the list of values is determined, and how it is used. Maxim's solution sounded from your posts that it will do. I never remember to consider solutions like that but there are often multiple approaches and the best needs to be determined based on the requirements on hand. |
#8
| |||
| |||
|
|
Hi Joel! does this count as a one sql statement solution? select 123 as abc from dual union select 456 from dual union select 789 from dual; I explicitly stated that I know that union could have been used and that I was looking for a solution that is easy to adapt from 1 to n rows. Don't misunderstand me, at this point I am not looking for "a" solution anymore, both my method and Maxim's solution work fine and yours would work, too, though it is less flexible. I just would like to learn more about sophisticated solutions regarding my problem to let me understand (Oracle) SQL better. Best, Hans |
#9
| |||
| |||
|
#10
| |||
| |||
|
|
Hi Maxim, Thanks. This is an elegant solution. However I wonder if there is a possibility which does not involve creating anything, just a plain "one sql statement solution" ... Best, Hans |
![]() |
| Thread Tools | |
| Display Modes | |
| |