我们可以在单个Oracle SQL中使用多个“WITH AS”吗?

21 浏览
0 Comments

我们可以在单个Oracle SQL中使用多个“WITH AS”吗?

我有一个非常简单的问题:Oracle允许在单个SQL语句中使用多个\"WITH AS\"吗?

例如:

WITH abc AS( select ......)
WITH XYZ AS(select ....) /*This one uses "abc" multiple times*/
Select ....   /*using XYZ multiple times*/

我可以通过多次重复相同的查询来使查询工作,但是我不想这样做,而是利用\"WITH AS\"。这似乎是一个简单的需求,但Oracle不允许我这样做:

ORA-00928:缺少SELECT关键字

admin 更改状态以发布 2023年5月20日
0
0 Comments

正确的语法是 -

with t1
as
(select * from tab1
where conditions...
),
t2
as
(select * from tab2
where conditions...
(you can access columns of t1 here as well)
)
select * from t1, t2
where t1.col1=t2.col2;

0
0 Comments

你可以这样做:\n

WITH abc AS( select
             FROM ...)
, XYZ AS(select
         From abc ....) /*This one uses "abc" multiple times*/
  Select 
  From XYZ....   /*using abc, XYZ multiple times*/

0