gpt4 book ai didi

oracle - 完全展开 View

转载 作者:行者123 更新时间:2023-12-01 01:38:30 25 4
gpt4 key购买 nike

在 Oracle 中,是否有一种简单的方法来完全展开 View ?例如:如果我有一个由更多 View 上的选择组成的 View ,是否有某种方法可以解开它以直接在真实表上选择?

最佳答案

in-line views的概念可用于执行此操作。假设您有以下 2 个 View :

create or replace view london_dept as
select * from dept
where loc = 'LONDON';


create or replace view london_mgr as
select * from emp
where job='MANAGER'
and deptno in (select deptno from london_dept);

在第二个 View 的 SQL 中,可以使用 london_dept View 定义中的 SQL 将 View london_dept 的引用替换为内嵌 View ,如下所示:
select * from emp 
where job='MANAGER'
and deptno in (select deptno from (select * from dept
where loc = 'LONDON'));

当然,您现在可以看到它过于冗长,可以简化为:
select * from emp 
where job='MANAGER'
and deptno in (select deptno from dept where loc = 'LONDON');

最后,Tom Kyte 关于创建 views of views 的优点和缺点的一些建议

关于oracle - 完全展开 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/137497/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com