如何执行使用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中执行此操作?
答案 0 :(得分:2)
子查询因子子句(WITH
子句)是单个查询的一部分,它有效地充当单次使用视图。如果您发现需要在多个查询的SELECT
子句中重复WITH
语句,则可能需要考虑为子查询因子子句中的每个SELECT
定义视图以简化代码。分享并享受。
答案 1 :(得分: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;
答案 2 :(得分:0)
你可以使用with子句作为GIVEN BELOW WITH WITH WITH WITH WITH 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
)
希望能帮助你。