我们正在重写最初包含6个CREATE / REPLACE VIEW的SQL脚本,因为我们的新应用程序无法在数据库中创建对象。要重写它,我们使用WITH关键字。
问题是,原始视图互相引用。在Oracle中是否允许这样做:
with
A as (select T1COL from Table1 ...),
B as (select NEWCOL from A ...) ,
..
答案 0 :(得分:2)
答案是:是的,这是可能的。
由于涉及大量代码,快速尝试它是不可行的。人们希望快速反应不会太困难
我为你准备了一个可运行的测试: http://sqlfiddle.com/#!4/9eecb7d/7884
WITH
a AS ( SELECT 'A' as T1COL FROM dual ),
b AS ( SELECT * FROM a ),
c AS ( SELECT * FROM b ),
d AS ( SELECT * FROM c ),
e AS ( SELECT * FROM d ),
f AS ( SELECT * FROM e ),
g AS ( SELECT * FROM f ),
h AS ( SELECT * FROM g ),
i AS ( SELECT * FROM h ),
j AS ( SELECT * FROM i ),
k AS ( SELECT * FROM j ),
l AS ( SELECT * FROM k ),
m AS ( SELECT * FROM l ),
n AS ( SELECT * FROM m ),
o AS ( SELECT * FROM n ),
p AS ( SELECT * FROM o ),
q AS ( SELECT * FROM p )
SELECT * FROM q;