oracle的merge语法
merge into trade.ttradeseat a
using trade.bs_zrt_tradeseat b
on (a.L_FUND_ID = b.l_Fund_Id and a.l_basecombi_id = b.l_basecombi_id and a.vc_seat_id = b.vc_seat_id and a.c_market_no = b.c_market_no)
when not matched then
insert
(L_FUND_ID, L_BASECOMBI_ID, VC_SEAT_ID, C_MARKET_NO, c_trade)
values
(b.L_FUND_ID, b.L_BASECOMBI_ID, b.vc_seat_id, b.c_market_no, b.c_trade);
merge语法是根据源表对目标表进行匹配查询,匹配成功时更新,不成功时插入。
其基本语法规则是
merge into 目标表 a
using 源表 b
on(a.条件字段1=b.条件字段1 and a.条件字段2=b.条件字段2 ……)
when matched then update set a.更新字段=b.字段
when not macthed then insert into a(字段1,字段2……)values(值1,值2……)
变种写法①,只更新:
merge into 目标表 a
using 源表 b
on(a.条件字段1=b.条件字段1 and a.条件字段2=b.条件字段2 ……)
when matched then update set a.更新字段=b.字段,a.更新字段2=b.字段2……
变种写法②,只插入:
merge into 目标表 a
using 源表 b
on(a.条件字段1=b.条件字段1 and a.条件字段2=b.条件字段2 ……)
when not macthed then insert into a(字段1,字段2……)values(值1,值2……)
注:条件字段不可更新
对于Oracle来说,merge是9i新增的语法,在10g进行了一些增强,如下:
测试环境:Oracle Database 11g Enterprise Edition Release 11.2.0.1.0
①条件操作:
merge into 目标表 a
using 源表 b
on(a.条件字段1=b.条件字段1 and a.条件字段2=b.条件字段2 ……)
when matched then update set a.更新字段=b.字段 where 限制条件
when not macthed then insert into a(字段1,字段2……)values(值1,值2……) where 限制条件
举例:
merge into test_merge a
using test b
on(a.no=b.no)
when matched then update set a.no2=b.no2 where a.no<>1
when not matched then insert values(b.no,b.no2) where a.no<>100
当然也支持变种①②的写法
②删除操作
merge into 目标表 a
using 源表 b
on(a.条件字段1=b.条件字段1 and a.条件字段2=b.条件字段2 ……)
when matched then update set a.更新字段=b.字段
delete where b.字段=xxx
举例:
merge into test_merge a
using test b
on(a.no=b.no)
when matched then update set a.no2=b.no2 where a.no<>1
delete
where b.no=14
备注:删除动作针对的也是目标表,并且必须在语句最后
基本上merge的用法就是以上这些,建议平常可以多用,比单独的update+insert的方式效率要更高,尤其是on条件下有唯一索引的时候,效率更高
oracle的merge语法的更多相关文章
- ORACLE中的MERGE语法使用记录
项目中使用到了Oracle的MERGE INTO语句,在这里简单记录下使用方法 使用场景如下: 存在对一张数据量很大的表,你需要对里面的大量数据进行更新,如果数据不存在,就进行插入的操作. 常规想到的 ...
- Oracle 使用MERGE INTO 语句更新数据
/*Merge into 详细介绍MERGE语句是Oracle9i新增的语法,用来合并UPDATE和INSERT语句.通过MERGE语句,根据一张表或子查询的连接条件对另外一张表进行查询,连接条件匹配 ...
- 转:Oracle中merge into的使用
最近项目上使用Oracle的Merge,所以找来一下资料学习了解. 该命令使用一条语句从一个或者多个数据源中完成对表的更新和插入数据. ORACLE 9i 中,使用此命令必须同时指定UPDATE 和I ...
- Oracle中merge into的使用
http://blog.csdn.net/yuzhic/article/details/1896878 http://blog.csdn.net/macle2010/article/details/5 ...
- Oracle中merge into的使用 (转)
该命令使用一条语句从一个或者多个数据源中完成对表的更新和插入数据. ORACLE 9i 中,使用此命令必须同时指定UPDATE 和INSERT 关键词,ORACLE 10g 做了如下改动. 1.ins ...
- Oracle中merge into的使用 (转)
http://blog.csdn.net/yuzhic/article/details/1896878 http://blog.csdn.net/macle2010/article/details/5 ...
- MERGE语法详解
merge语法是根据源表对目标表进行匹配查询,匹配成功时更新,不成功时插入. 其基本语法规则是 merge into 目标表 a using 源表 b on(a.条件字段1=b.条件字段1 and a ...
- (转)MERGE语法详解
merge语法是根据源表对目标表进行匹配查询,匹配成功时更新,不成功时插入. 其基本语法规则是 merge into 目标表 a using 源表 b on(a.条件字段1=b.条件字段1 and a ...
- Oracle存储过程基本语法介绍
Oracle存储过程基本语法 存储过程 1 CREATE OR REPLACE PROCEDURE 存储过程名 2 IS 3 BEGIN 4 NULL; 5 END; 行1: CREATE OR RE ...
随机推荐
- Unity进阶之ET网络游戏开发框架 07-修正游客登录的异步BUG
版权申明: 本文原创首发于以下网站: 博客园『优梦创客』的空间:https://www.cnblogs.com/raymondking123 优梦创客的官方博客:https://91make.top ...
- appium+python自动化64-使用Uiautomator2执行driver.keyevent()方法报错解决
前言 未加'automationName': 'Uiautomator2'参数使用Uiautomator可以正常使用driver.keyevent()方法,使用Uiautomator2时driver. ...
- ThinkPHP远程调用模块的操作方法 URL 参数格式
* 远程调用模块的操作方法 URL 参数格式 [项目://][分组/]模块/操作 * @param string $url 调用地址 * @param string|array $vars 调用参数 ...
- robot framework 笔记(三),RF安装
背景: 本来robot framework的安装应该放在一开始写的,因写博客的时候已经装过了,恰巧重装系统又重装了一遍RF RF推荐使用python2, 使用3的话会遇到一些页面非友好的问题 需要的安 ...
- zabbix4.2.5默认告警模板
产生告警: Problem: {EVENT.NAME} Problem started at {EVENT.TIME} on {EVENT.DATE} Problem name: {EVENT.NAM ...
- 【转】RabbitMQ三种Exchange模式
[转]RabbitMQ三种Exchange模式 RabbitMQ中,所有生产者提交的消息都由Exchange来接受,然后Exchange按照特定的策略转发到Queue进行存储 RabbitMQ提供了四 ...
- SpringBoot整合Bubbo
一.创建springboot_dubbo_provider项目 1 创建service层接口 public interface IDoSomeService { public String sayHi ...
- Tensorflow细节-Tensorboard可视化-简介
先搞点基础的 注意注意注意,这里虽然很基础,但是代码应注意: 1.从writer开始后边就错开了 2.writer后可以直接接writer.close,也就是说可以: writer = tf.summ ...
- Postgresql operator does not exist: numeric = character varying
)),series_name from svcm_t_series_res: 原来series_id是numeric型,现在转换为varchar(64):
- 浅谈H5图片中object-fit的属性及含义/ 小程序image mode属性中scaleToFill,aspectFit,widthFix等类似
我们在H5中对于图片的属性包含如下: object-fit属性有哪些值呢? object-fit: fill; object-fit: contain; object-fit: cover; o ...