网站首页 > 技术文章 正文
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 安装
你 发表评论:
欢迎- 最近发表
- 标签列表
-
- 前端设计模式 (75)
- 前端性能优化 (51)
- 前端模板 (66)
- 前端跨域 (52)
- 前端缓存 (63)
- 前端aes加密 (58)
- 前端脚手架 (56)
- 前端md5加密 (54)
- 前端路由 (61)
- 前端数组 (73)
- 前端js面试题 (50)
- 前端定时器 (59)
- Oracle RAC (76)
- oracle恢复 (77)
- oracle 删除表 (52)
- oracle 用户名 (80)
- oracle 工具 (55)
- oracle 内存 (55)
- oracle 导出表 (62)
- oracle约束 (54)
- oracle 中文 (51)
- oracle链接 (54)
- oracle的函数 (58)
- oracle面试 (55)
- 前端调试 (52)
本文暂时没有评论,来添加一个吧(●'◡'●)