如何在 Oracle 中创建下表。
+------+------+
| col1 | col2 |
+------+------+
| A | 1 |
| B | 2 |
+------+------+
我需要它作为 WITH 子句中的中间表。
如何在 Oracle 中创建下表。
+------+------+
| col1 | col2 |
+------+------+
| A | 1 |
| B | 2 |
+------+------+
我需要它作为 WITH 子句中的中间表。
您可以使用:
with t as (
select 'A' as col1, 1 as col2 union all
select 'B' as col1, 2 as col2
)
然后,您可以t
在查询的其余部分中使用。
当您创建这样的公用表表达式时,您可以在 CTE 定义中命名列,这样可以避免将它们分散在 SELECT 语句中:
WITH cteWork (COL1, COL2) AS
(SELECT 'A', 1 FROM DUAL UNION ALL
SELECT 'B', 2 FROM DUAL)
SELECT *
FROM cteWork
请使用以下查询,
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;