How can I create the following table in Oracle.
+------+------+
| col1 | col2 |
+------+------+
| A | 1 |
| B | 2 |
+------+------+
I need it as an itermediate table in a WITH-clause.
You can use:
with t as (
select 'A' as col1, 1 as col2 union all
select 'B' as col1, 2 as col2
)
You can then use t
throughout the rest of the query.
Please use below query,
with tbl as
(
select 'A' as col1, 1 as col2 from dual
UNION
select 'B' as col1, 2 as col2 from dual
)
select * from tbl;
When you create a common table expression such as this you can name the columns in the CTE definition, which saves having them scattered through the SELECT statement:
WITH cteWork (COL1, COL2) AS
(SELECT 'A', 1 FROM DUAL UNION ALL
SELECT 'B', 2 FROM DUAL)
SELECT *
FROM cteWork
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.