视图是我们开发过程中经常打交道的对象,不知道你在写视图时有没有犯过这样的错误:
create or replace view test_view as
select b.emp_no,
b.salary
from emp a,emp_salary b
WHERE a.emp_no = b.emp_no(+)
emp表中有个emp_no为123的员工,在emp_salary中没有记录,当你用select * from test_view where emp_no=123时,你会发现根本查不到信息,而在视图里面写外连接的作用就是为了在这种场景下能够查得出信息,但是为什么查不到信息了?
原因就是select * from test_view where emp_no=123 相当于
select b.emp_no,
b.salary
from emp a,emp_salary b
WHERE a.emp_no = b.emp_no(+)
AND b.emp_no = 123
这样就可以清楚看到,这样写外关联根本没起到作用(因为只在emp_salary一个条件上用了外关联),
所以大家在写视图的时候千万要注意,不要把外关联表的列作为查询条件。。。。