Can I have something like
SELECT (1, 2, 4542, 342) FROM DUAL;
and get it like this?
| 1 |
| 2 |
| 4542 |
| 342 |
When you select an expression say 1 from a table (can be dual or any other table), it will return the expression depending on the number of rows in the table. Eg:- Select 1 from dual; returns 1 as there is only one record in dual.
Thus, we can use INSERT-SELECT-UNION query to insert data into multiple rows of the table. The SQL UNION query helps to select all the data that has been enclosed by the SELECT query through the INSERT statement.
DUAL table has one column, DUMMY, defined to be VARCHAR2(1), and contains one row with a value X. Selecting from the DUAL table is useful for computing a constant expression with the SELECT statement. Because DUAL has only one row, the constant is returned only once.
Instead of DUAL
, combine the TABLE
operator with a pre-built collection to return multiple rows. This solution has a small syntax, avoids type conversions, and avoids potentially slow recursive queries. But it's good to understand the other solutions as well, they are all useful in different contexts.
select * from table(sys.odcinumberlist(1, 2, 4542, 342));
Well if (1, 2, 4542, 342)
were a string you could do this:
with cte as (
SELECT '1, 2, 4542, 342' as str
FROM DUAL
)
select regexp_substr(str,'[^,]+',1,level)
from cte
connect by level <= regexp_count(str, ',')+1
/
No. dual
has just one row, but you can use union all
:
SELECT 1 FROM DUAL UNION ALL
SELECT 2 FROM DUAL UNION ALL
SELECT 4542 FROM DUAL UNION ALL
SELECT 342 FROM DUAL;
This is just one way to generate a table "on-the-fly" in Oracle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With