日期:2014-05-17  浏览次数:20938 次

oracle视图关联的问题
有两张表 table a,table b
table a 格式如下:

product_id a_num
  10001 145
  10002 1156
  10003 1515
  10004 152
  10005 158
  .............

table b 格式如下:
product_id b_num
  10001 4664
  10002 154
  10003 452

table b 的行数比table a少,
想建一个视图,由tablea.product_id,tablea.a_num,tableb.b_num组成。
create or replace view v_c as
select a.product_id,a.a_num,b.b_num
from tablea a,tableb b
where a.product_id = b.produt_id
可是建成以后发现视图的查询结果只有b表中的三行数据,不是我想要的a表中的五行数据。
我想达到的效果是,视图中数据的行数跟a表一致,b_num在b表中对应没有的,自动填充0
如何才能达到那样的效果呢?

------解决方案--------------------
具体记不清了,两者均试一下:

create or replace view v_c as 
select a.product_id,a.a_num,b.b_num 
from tablea a,tableb b 
where a.product_id(+) = b.produt_id;

create or replace view v_c as 
select a.product_id,a.a_num,b.b_num 
from tablea a,tableb b 
where a.product_id = b.produt_id(+);
 

------解决方案--------------------
create or replace view v_c as 
select a.product_id,a.a_num,b.b_num 
from tablea a,tableb b 
where a.product_id = b.produt_id(+);