【发布时间】:2022-11-24 20:34:21
【问题描述】:
我有一个查询,是这样的:
select col1,col2 from (
with RESULTSET as (
select * from t1 where rank_val=1
)
select T1.col1, T1.col2
FROM RESULTSET T1, t88a, t88b
where T1.col1=T88a.col1 and T88a.col2 = T1.col2
AND T1.col2=T88b.col2 and T88b.col1 <> T1.col1
) where NOT (c1 IS NULL AND c2 IS NULL) ORDER BY col1, col2;
我有一个要求,我需要使用一个外部With As,如下所示:
WITH NEW AS(select col1,col2 from (
with RESULTSET as (
select * from t1 where rank_val=1
)
select T1.col1, T1.col2
FROM RESULTSET T1, t88a, t88b
where T1.col1=T88a.col1 and T88a.col2 = T1.col2
AND T1.col2=T88b.col2 and T88b.col1 <> T1.col1
) where NOT (c1 IS NULL AND c2 IS NULL) ORDER BY col1, col2)
SELECT * FROM NEW;
它给了我例外:
ORA-32034: unsupported use of WITH clause
32034. 00000 - "unsupported use of WITH clause"
如何通过删除内部 With As 来重新编写查询。
【问题讨论】:
-
你不能嵌套我认为的那些,但你可以在单个
with子句中包含多个:with ALIAS1 as (Query1), ALIAS2 as (Query2), ALIAS3 as (Query3) select ....。每个查询都可以使用先前定义的别名。 -
@jarlh 其 Oracle Database 19c 企业版 Release 19.0.0.0.0
-
为了帮助您找到它们的文档,这些子句称为“公用表表达式”,通常缩写为“CTE”。