1

如何执行使用WITH.准备的数据的多条语句 例如:

WITH t1 AS
(
 ....using some table
),
t2 as
(
....using t1 and some other tables
),
t3 as
(
..using t1 and t2 and some other tables
)
statement 1; (let say this is using t1 and t2)
statement 2; (let say this is using t2 and t3)

我怎样才能在 Oracle 中做到这一点?

4

3 回答 3

2

子查询因式分解子句 ( WITHclause) 是单个查询的一部分,它有效地充当一次性视图。如果您发现需要在多个查询SELECT的子句中重复语句,WITH您可能需要考虑SELECT在子查询因式分解子句中为每个子句定义视图以简化代码。分享和享受。

于 2013-07-25T11:08:47.677 回答
0

例如:

-- Block With
--------------------------------------------------------------------------------
with
w1 as
(
select 1 as id
       , '123' as text
from dual
)

, w2 as
(
select w1.*
from w1
)

, w3 as
(
select w2.*
from w2
)
-- End Block With
--------------------------------------------------------------------------------

select * from w1, w2, w3;
于 2013-07-25T10:11:29.253 回答
0

您可以将 with 子句用作 GIVEN BELOW FOR USE WITH MULTIPLE WITH BLOCKS

WITH 
t1
AS (
      SELECT  column1, column2
      FROM   some_tables                  
            ),
t2 as 
(
       SELECT column4,column4
       FROM some tables
)                
SELECT column5,column6 --USE ALIAS OF THE ABOVE BLOCKS YOU HAVE CREATED DOWN AND USE THEM AND SELECT THE IN BASE QUERY
            FROM
            (
                SELECT column1 COLUMN 5,column2 COLUMN 6
                FROM   t1 a
                union ALL
                SELECT column3 COLUMN 5,column4 COLUMN 6
                FROM   t2 a

                )

希望会有所帮助。

于 2013-07-25T21:31:17.977 回答