网站首页 > 技术文章 正文
merge into是一个dml语句,也需要通过rollback和commit 结束事务。
UPDATE或INSERT子句可以二选一。
10g之前必须insert into和update都要存在,不是update就是insert,只能二选一。而10g里就是可选了。
比如下面的例子,可以只存在update或者insert
merge into oldproducts op using newproducts np on (op .product_id = np.product_id)
when matched then
update set op.product_name = np.product_name
以上例子说明有匹配的时候就更新,不匹配的情况下就不处理了。
2. UPDATE和INSERT子句可以加上WHERE子句
这也是一个功能性的改进,这个where的作用是一个过滤的条件,加入一些额外的条件,对只对满足where条件的进行update和insert
merge into oldproducts op using (select * from newproducts) np on (op.product_id = np.product_id)
when matched then
update set op.product_name = np.product_name where np.product_name like 'LV%'
insert里也可以加入where,比如
merge into oldproducts op using (select * from newproducts) np on (op.product_id = np.product_id)
when matched then
update set op.product_name = np.product_name where np.product_name like 'LV%'
when not matched then
insert values(np.product_id, np.product_name, np.category) where np.product_name like 'LV%'
3. 在ON条件中使用常量过滤条件来insert所有的行到目标表中,不需要连接源表和目标表
merge into oldproducts op using (select * from newproducts) np on (1=0)
when matched then
update set op.product_name = np.product_name
when not matched then
insert values(np.product_id, np.product_name, np.category)
4. UPDATE子句后面可以通过DELETE子句来去除一些不需要的行,delete只能和update配合,从而达到删除满足where条件的子句的纪录
merge into oldproducts op using (select * from newproducts) np on (p.product_id = np.product_id)
when matched then
update set op.product_name = np.product_name delete where op.product_id = np.product_id where np.product_name like 'LV%'
when not matched then
insert values(np.product_id, np.product_name, np.category)
猜你喜欢
- 2024-10-24 oracle10g高级安装 oracle10.2安装
- 2024-10-24 oracle 10g使用exp管道压缩方式减小文件大小
- 2024-10-24 Oracle 10g 客户端数据库配置不可缺几个步骤!
- 2024-10-24 win2012,2016 能安装oracle 10g吗?
- 2024-10-24 Oracle10g软件安装方法 oracle10怎么安装
- 2024-10-24 oracle 10G安装教程 oracle10g安装教程
- 2024-10-24 Oracle10g的安装步骤-附图详细 oracle10 安装
你 发表评论:
欢迎- 616℃几个Oracle空值处理函数 oracle处理null值的函数
- 609℃Oracle分析函数之Lag和Lead()使用
- 598℃0497-如何将Kerberos的CDH6.1从Oracle JDK 1.8迁移至OpenJDK 1.8
- 594℃Oracle数据库的单、多行函数 oracle执行多个sql语句
- 590℃Oracle 12c PDB迁移(一) oracle迁移到oceanbase
- 581℃【数据统计分析】详解Oracle分组函数之CUBE
- 571℃最佳实践 | 提效 47 倍,制造业生产 Oracle 迁移替换
- 560℃Oracle有哪些常见的函数? oracle中常用的函数
- 最近发表
-
- PageHelper - 最方便的 MyBatis 分页插件
- 面试二:pagehelper是怎么实现分页的,
- MyBatis如何实现分页查询?(mybatis-plus分页查询)
- SpringBoot 各种分页查询方式详解(全网最全)
- 如何在Linux上运行exe文件,怎么用linux运行windows软件
- 快速了解hive(快速了解美国50个州)
- Python 中的 pyodbc 库(pydbclib)
- Linux搭建Weblogic集群(linux weblogic部署项目步骤)
- 「DM专栏」DMDSC共享集群之部署(一)——共享存储配置
- 故障分析 | MySQL 派生表优化(mysql pipe)
- 标签列表
-
- 前端设计模式 (75)
- 前端性能优化 (51)
- 前端模板 (66)
- 前端跨域 (52)
- 前端缓存 (63)
- 前端aes加密 (58)
- 前端脚手架 (56)
- 前端md5加密 (54)
- 前端路由 (61)
- 前端数组 (73)
- 前端js面试题 (50)
- 前端定时器 (59)
- 前端获取当前时间 (50)
- Oracle RAC (76)
- oracle恢复 (77)
- oracle 删除表 (52)
- oracle 用户名 (80)
- oracle 工具 (55)
- oracle 内存 (55)
- oracle 导出表 (62)
- oracle约束 (54)
- oracle 中文 (51)
- oracle链接 (54)
- oracle的函数 (58)
- 前端调试 (52)
本文暂时没有评论,来添加一个吧(●'◡'●)