集合操作
集合操作
union 并集 去除重復值
union all 也是并集 不去除重復值
例:
select employee_id, job_id from employees
union all
select employee_id, job_id from job_history;
select employee_id, job_id from employees
union
select employee_id, job_id from job_history;
intersect 交集
select employee_id, job_id from employees
intersect
select employee_id, job_id from job_history;
minus 差集
select employee_id from employees
minus
select employee_id from job_history;
select employee_id, job_id, salary from employees
union all
select employee_id, job_id, null from job_history;
// 如果不能提供這個值 就用空值代替
集合排序:
select employee_id, job_id, salary from employees
union all
select employee_id, job_id, null from job_history
order by salary;
//order by只寫一個 寫在最后一個后面
select employee_id, job_id, null from job_history
union all
select employee_id, job_id, salary from employees
order by 3;
如果沒有名字就用第幾列或者用別名
DML
insert:
SQL> create table t1(x int, y char(1), z date);
SQL> insert into t1(x, y, z) values (1, 'a', sysdate);
SQL> insert into t1(x, z, y) values (2, sysdate+1, 'b');
SQL> insert into t1(x, y, z) values (1, null, sysdate);
SQL> insert into t1(x, z) values (2, sysdate+1);
SQL> insert into t1 values (1, null, sysdate)
//insert 定義列 列的聲明 values 后面加列的值
create table my_emp as select * from employees; //復制表 只復制了數據和基本結構 沒有附加結構
SQL> create table my_emp as select * from employees where 1=0;// 一張空的表 復制表結構 后面where 1=0 不可能實現所以查詢的是空的
?
update 更新
SQL> update my_emp set salary=salary*1.1;
SQL> update my_emp set salary=salary*1.1 where department_id=50;
SQL> update my_emp set salary=salary*1.1, commission_pct=0.5 where employee_id=197;
//定位行 更新列
在new_dept表中刪除沒有員工的部門
SQL> create table my_dept as select * from departments;
delete from my_dept outer
where not exists
(select 1 from my_emp
where department_id=outer.department_id);
?
delete和truncate: delete truncate
語句類型 dml ddl
undo數據 產生大量undo數據 不產生undo數據
空間管理 不釋放 釋放
語法 where 刪除全部數據
轉載于:https://www.cnblogs.com/luo102154/p/7270496.html
總結
- 上一篇: 败家MM
- 下一篇: Gartner公布2017年十大战略科技