我是靠谱客的博主 会撒娇树叶,这篇文章主要介绍minus,union,union all,intersect 这几个的区别和用法,现在分享给大家,希望可以做个参考。

/*minus:只取不重复的记录*/
   select count(1) into vn_count
                   from (select t.*, t.rowid from emp t
                   minus
                   select s.*, s.rowid from emp s);
   dbms_output.put_line('minus rows in table emp is:' || vn_count);   
              
/*union: 取两个查询记录(去掉重复的)**/
   select count(1)  into vn_count
                    from (select t.*, t.rowid from emp t
                    union
                    select s.*, s.rowid from emp s);
   dbms_output.put_line('union rows in table emp is:' || vn_count);   
                   
/*union all: 取两个查询所有的记录(包括重复的)**/
   select count(1) into vn_count
                     from (select t.*, t.rowid from emp t
                     union all
                     select s.*, s.rowid from emp s);
  dbms_output.put_line('union all rows in table emp is:' || vn_count);     
                     
/*intersect: 只取重复的记录(相当于交集吧)*/   
   select count(1)into vn_count
                      from (select t.*, t.rowid from emp t
                      intersect
                      select s.*, s.rowid from emp s);

最后

以上就是会撒娇树叶最近收集整理的关于minus,union,union all,intersect 这几个的区别和用法的全部内容,更多相关minus,union,union内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(105)

评论列表共有 0 条评论

立即
投稿
返回
顶部