--union  并集
select * from emp where ename like '%A%' union
select * from emp where ename like '%M%';
--union all 集并 公共部分 会包含二次
select * from emp where ename like '%A%'
union all
select * from emp where ename like '%M%';
--intersert交集
select * from emp where ename like '%A%'
intersect
select * from emp where ename like '%M%';
--minus求差集 S1: A - (S1&S2 union)1100-1200
select * from emp where sal between 700 and 1200 --700-1100;
minus
select * from emp where sal between 1100 and 1500; --联合与全联合运算
--union
create table emp_history as select * from emp ;--辅助 select empno,ename,sal,hiredate,deptno
from emp where deptno =20
union
select empno,ename,sal,hiredate,deptno
from emp_history where deptno =30
order by deptno; -- union all 不能消除重复行,不能输出排序 使用DISTINCT关键字
select empno,ename,sal,hiredate,deptno
from emp where deptno =20
union all
select empno,ename,sal,hiredate,deptno
from emp_history where deptno =30
order by deptno; --相交运算 1.列数和数据类型与select语句一样,但列名可以不同 select empno,ename,sal,hiredate,deptno from emp
where deptno =20 intersect
select empno,ename,sal,hiredate,deptno from emp_history
where deptno=20; --相减运算
--查询在第一个表中而不再第二个表中的行
select empno,ename,sal,hiredate,deptno from emp
where deptno=20
minus
select empno,ename,sal,hiredate,deptno from emp
where deptno=20;
--结构化查询 实现递归表的查询
select * from emp;
select level,lpad(' ',2*(level-1))||ename, empno,mgr,hiredate,sal from emp
start with mgr is null --start with以manager_id is null作为跟节点
connect by prior empno=mgr;
--根据connect by prior规则,继续向下寻找,形成树状结构查询 --用子查询插入数据
create table emp_copy as select * from emp where 1=2;
insert into emp_copy select * from emp where deptno=20;
--insert插入多表数据
create table emp_dept_10 as select * from emp where 1=2;
create table emp_dept_20 as select * from emp where 1=2;
create table emp_dept_30 as select * from emp where 1=2;
insert first
when deptno =10
then
into emp_dept_10
when deptno=20
then
into emp_dept_20
when deptno=30
then
into emp_dept_30
else
into emp_copy
select * from emp; select * from emp_dept_10;
--Merge语句
merge into emp_copy c --目标表
using emp e on (c.empno=e.empno) --源表,可以是表,视图或查询
when MATCHED then update --当匹配时,进行update操作
set c.ename=e.ename,c.job=e.job,c.mgr=e.mgr,
c.hiredate=e.hiredate,c.sal=e.sal,c.comm=e.comm,
c.deptno =e.deptno
when not matched then
insert
values(e.empno,e.ename,e.job,e.mgr,e.hiredate,e.sal,e.comm,
e.deptno); create table dept60_bonuses
(
empno number,bonus_amt number
);
insert into dept60_bonuses values(7369,0);
insert into dept60_bonuses values(7788,2);
insert into dept60_bonuses values(7876,3);
select empno,sal,ename from emp;
select * from dept60_bonuses;
--合并两张表,根据不同的语句删除,更新
merge into dept60_bonuses b
using ( select empno,sal,deptno from emp where deptno=20) e
on (b.empno=e.empno)
when matched then
update set b.bonus_amt =e.sal*0.2
where b.bonus_amt=0
delete where (e.sal>2500)
when not matched then
insert (b.empno,b.bonus_amt)
values (e.empno,e.sal*0.1)
where (e.sal<4000);
使用TRUNCATE清除表数据
与delete语句相比,使用truncate命令速度更快,原因 DTL
1不会激活表的删除触发器
2 属于数据定义语言,不会产生撤销信息
3 主外键关系无法清除表内容,必须禁用约束
不能使用PLSQL语句块 直接调用
--禁用约束
alter table dept disable constraint pk_dept cascade;
提交 commit; 回滚 rollback;
--sql>
create table jobs (adds varchar2(10),jname varchar2(20),sal number(10),comm number(10));
delete from jobs;
insert into jobs values('OFFICE','办公文员',3000,5000);
savepoint sp;
insert into jobs values('FINANCE','财务人员',4000,8000);
select * from jobs;
rollback to savepoint sp;
使用集合方法
--exits 方法 集合的坐标元素是否存在
declare
type projectlist is varray (50) of varchar2(16);
project_list projectlist:=projectlist('网站','ERP','CRM','CMS');
begin
if project_list.exists(5)
then
dbms_output.put_line('元素存在,其值为:'||project_list(5));
else
dbms_output.put_line('元素不存在');
end if;
end;

Oracle集合的更多相关文章

  1. Oracle集合操作函数:union、intersect、minus

    [转]Oracle集合操作函数:union.intersect.minus 集合操作符专门用于合并多条select 语句的结果,包括:UNION, UNION ALL, INTERSECT, MINU ...

  2. oracle 集合变量以及自定义异常的用法

    oracle 集合变量以及自定义异常的用法, 在过程 record_practice 有record变量和自定义异常的用法实例.具体在3284行. CREATE OR REPLACE Package ...

  3. Oracle集合类型

    Oracle集合类型介绍   集合类型   1. 使用条件:    a. 单行单列的数据,使用标量变量 .     b. 单行多列数据,使用记录    c. 单列多行数据,使用集合        *集 ...

  4. oracle 集合定义

    集合:是具有相同定义的元素的聚合.Oracle有两种类型的集合: 可变长数组(VARRAY):可以有任意数量的元素,但必须预先定义限制值. 嵌套表:视为表中之表,可以有任意数量的元素,不需要预先定义限 ...

  5. Oracle集合操作

    在Oracle中提供了三种类型的集合操作: 并(UNION).交(INTERSECT).差(MINUS) UNION:将多个查询的结果组合到一个查询结果之中,并去掉反复值 UNION ALL:将多个查 ...

  6. Oracle 集合操作

    在 Oracle 中提供了三种类型集合操作:并(UNION).交(INTERSECT).差(MINUS) · UNION:将多个查询的结果组合到一个查询结果之中,没有重复内容 · UNION ALL: ...

  7. 【database】oracle集合 - Associative Arrays、Varrays、Nested Tables

    前言 参考oracle官方文档:PL/SQL Language Reference 11g Release 2  -  5 PL/SQL Collections and Records 可以去看下文档 ...

  8. 【转】Oracle集合操作函数:union、intersect、minus

    集合操作符专门用于合并多条select 语句的结果,包括:UNION, UNION ALL, INTERSECT, MINUS.当使用集合操作符时,必须确保不同查询的列个数和数据类型匹配. 集合操作符 ...

  9. Oracle集合运算符 交集 并集 差集

     集合运算符:UNION/UNION ALL 并集,INTERSECT 交集,MINUS 差集  一.union求并集,公共部分只有包含一次 例:求emp表ename中含’A‘或含有‘M’ SQL&g ...

  10. oracle 集合运算符

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAY4AAACNCAIAAAAvhQoxAAAbmklEQVR4nO1dX6jc1pn/0lBH4KVV6J ...

随机推荐

  1. Segmentation fault (core dumped) 错误的一种解决场景

    错误类型 Segmentation fault (core dumped) 产生原因 Segmentation fault 段错误. Core Dump 核心转储(是操作系统在进程收到某些信号而终止运 ...

  2. C# lambda 和 Linq

    本章节给大家带来的是Lambda 和 Linq 的关系 Lambda : 是实例化委托的一个参数,也就是一个方法 Linq:是基于委托(lambda)的封装,代码重用,逻辑解耦,是一个帮助类库,lin ...

  3. angular setInterval计时操作

    在angular中setInterval方法是单向绑定,只绑定一次,无法实现计时效果, 可以使用$interval实现.附上代码:

  4. Spring 约束文件配置

    1.引入jar包 2.新建applicationContext.xml配置文件 位置随意,建议放在src目录下 新建的空xml文件,写入一对beans标签 3.打开Windows-->Prefe ...

  5. php wamp基础环境搭建

    一.apache 安装配置: 1.安装apache 1.1 下载地址:https://www.apachelounge.com/download/ 1.2 将下载的文件解压到你想安装的目录 D:\WA ...

  6. Delphi XE7调用Java Class,JAR

    Delphi XE5,XE6需要用户手工编译并将Classes.Dex加入到包中,不过Delphi XE7可以省掉这些工作了. 如何在XE7中调用Java,具体步骤如下: 1.将jar文件添加到XE7 ...

  7. CentOS6安装各种大数据软件 第三章:Linux基础软件的安装

    相关文章链接 CentOS6安装各种大数据软件 第一章:各个软件版本介绍 CentOS6安装各种大数据软件 第二章:Linux各个软件启动命令 CentOS6安装各种大数据软件 第三章:Linux基础 ...

  8. jdbc之存储过程的调用和调用方法

    调用存储过程 调用存储过程的sql语句 {call 过程名称(参数列表)} conn = DbUtils.getConnection(); sql = "{call p_order_appr ...

  9. Go语言中结构体的使用-第2部分OOP

    1 概述 结构体的基本语法请参见:Go语言中结构体的使用-第1部分结构体.结构体除了是一个复合数据之外,还用来做面向对象编程.Go 语言使用结构体和结构体成员来描述真实世界的实体和实体对应的各种属性. ...

  10. T脚本语言学习记录-工具(一)

    1.set & unset %set a Hello ;#定义变量 a 并赋值 =>Hello %puts $a ;#输出变量值 =>Hello %set a “Test Tcl” ...