Oracle从小白到精通第七天( set运算符)(尚硅谷学习Oracle笔记)
Oracle学习笔记
1.set操作符的基本含义
-
一般有union,union all ,intersect 和minus这么几种
union去除重复的,union all不去除重复的,intersect取交集,minus差集
创建两个表
表一
create table employees01
as
select *
from employees
where department_id in(70,80)
表二
create table employees02
as
select *
from employees
where department_id in(90,80)
进行union操作
select employee_id emp_id,department_id
from employees02
union
select employee_id,department_id
from employees01
order by emp_id desc
其中select中的列要一一对应
列名可以更改,不过以上面那个表为主
其他的union all,intersect,minus同union -
如果两个表对应不上去的时候应该怎么做
在对应的位置上添加null
select employee_id,department_id,to_char(null)
from employees01
union
select to_number(null),department_id,department_name
from departments
让一个列不打印
column a_dummy noprint;
order by 2是根据哪一列进行排序
a_dummy是定义一个不打印列的列名