oracle的union视图问题

oracle中视图使用union连接建立两个视图后,再使用union将两个视图连接成一个视图,为什么select出来的数据比两个视图的总个数少,注(使用union all)

第1个回答  2013-03-28
union 是合并重复项的
比如视图A
id value
1 1
2 2
3 3

视图B
id value
1 2
1 1

union后,只保留一个
id value
1 1
最后结果只有四条

你要保留所有要用union all
这样结果才是五条记录
select * from A
union all
select * from B追问

我连接的时候就是使用的union all,而且查询的两次的结果条数还不同

追答

你看你视图是怎么建的,是不是视图里的表的数据发生变化了

本回答被提问者采纳
第2个回答  2013-03-28
你把建视图的语句和查询语句都贴出来看看呗追问

第一个视图:create or replace view leave_out as select a.info,a.id,a.user_id,a.begin_time start_time,a.end_time end_timr, '1'typed
from B_ATT_FLOW_LEAVE a where a.Bmjlqz = '审批通过'
union all 连接另一个表
第二个视图跟第一个差不多的,之后的合并查询的:
select * from holiday_meet
union all
select * from leave_out_btravel

追答

应该不会有问题啊,你select count() from 视图1 ,和select count(*) from 视图2 的和

select count(*) from
(select * from 视图1
union all
select * from 视图2)不一样吗?

相似回答