当前位置: 首页 > news >正文

网站备案费用沈阳网站优化

网站备案费用,沈阳网站优化,网站备案授权书模板,长沙房地产集团文章目录 merge into使用场景merge into语法测试表普通模式 merge使用注意点 merge into MERGE 是 Oracle9i 新增的语法,根据源表对目标表进行匹配查询,匹配成功时更新,不成功时插入 比单独的 update insert 的方式效率要更高,尤…

文章目录

  • merge into
  • 使用场景
  • merge into语法
  • 测试表
    • 普通模式
  • merge使用注意点

merge into

MERGE 是 Oracle9i 新增的语法,根据源表对目标表进行匹配查询,匹配成功时更新,不成功时插入
比单独的 update + insert 的方式效率要更高,尤其是on条件下有唯一索引的时候,效率更高。

使用场景

在写数据同步的脚本时,常常会遇到这样的需求:存在时更新,不存在时插入

merge into语法

MERGE INTO [target-table] T  --目标表 可以用别名
USING [source-table] S  --数据源表 可以是表、视图、子查询
ON([conditional expression] )  --关联条件
WHEN MATCHED THEN --当关联条件成立时 更新、删除,插入的where部分为可选 
UPDATE [target-table] SET T.column = S.column WHERE 限制条件
DELETE [target-table] WHERE 限制条件
WHEN NOT MATCHED THEN --当关联条件不成立时   
INSERT (column,...) VALUES('',...)

判断源表 S 和目标表 T 是否满足 ON 中的条件,如果满足则用 S 表去更新 T 表,如果不满足,则将 S 表数据插入 T 表中。但是有很多可选项,如下:

  • 普通模式
  • 只 update 或者只 insert
  • 无条件 insert 实现
  • 带 delete 的 update

测试表

-- 目标表
CREATE TABLE target ( ID NUMBER NOT NULL, NAME VARCHAR2 ( 12 ) NOT NULL, YEAR NUMBER 
);
-- 源表
CREATE TABLE source (ID NUMBER NOT NULL,AID NUMBER NOT NULL,NAME VARCHAR2 ( 12 ) NOT NULL,YEAR NUMBER,CITY VARCHAR2 ( 12 ) 
);
-- 插入测试数据
INSERT INTO target
VALUES( 1, 'liuwei', 20 );
INSERT INTO target
VALUES( 2, 'zhangbin', 21 );
INSERT INTO target
VALUES( 3, 'fuguo', 20 );
INSERT INTO source
VALUES( 1, 2, 'zhangbin', 30, '吉林' );
INSERT INTO source
VALUES( 2, 4, 'yihe', 33, '黑龙江' );
INSERT INTO source
VALUES( 3, 3, 'fuguo', '', '山东' );

普通模式

merge使用注意点

1、如果using中的语句查询不出来数据,是不会执行insert方法的,因为这个语法是根据using 中的查询数据进行判断

merge into student a
using (select id  from student where id = '7') s
on (a.id = s.id )
when matched thenupdate set a.student_name = '小明二号'
when not matched theninsert (id, student_name, fk_class) values ('7', '小明', '2')

2、on 中的条件记得过滤准确,不然可能会执行全表更新

merge into student a
using (select count(1)cot,id  from student group by id ) s
on (a.id = s.id and cot > 0)
when matched thenupdate set a.student_name = '小明二号'
when not matched theninsert (id, student_name, fk_class) values ('7', '小明', '2')

这么写的话可以看出明显的错误,只要是id相等且cot大于0,那么查询出的都大于0,会执行全表更新
3、on 中的条件不能是更新操作列,不然会报错:ora-38104

merge into student a
using (select '7' as id from dual) s
on (a.id = s.id)
when matched thenupdate set a.id = '7'
when not matched theninsert (id, student_name, fk_class) values ('7', '小明', '2');

参考:
https://blog.csdn.net/weixin_44657888/article/details/124591434

https://www.jianshu.com/p/8f51ce60d9ba


文章转载自:
http://gargle.c7501.cn
http://cardioversion.c7501.cn
http://ogrish.c7501.cn
http://dolichomorphic.c7501.cn
http://bunchgrass.c7501.cn
http://magnetization.c7501.cn
http://ifac.c7501.cn
http://lancang.c7501.cn
http://motoneuron.c7501.cn
http://habana.c7501.cn
http://laloplegia.c7501.cn
http://proponent.c7501.cn
http://aristotle.c7501.cn
http://dactylic.c7501.cn
http://duodenitis.c7501.cn
http://recombination.c7501.cn
http://bootblack.c7501.cn
http://vectorscope.c7501.cn
http://moctezuma.c7501.cn
http://refer.c7501.cn
http://poecilitic.c7501.cn
http://suilline.c7501.cn
http://tidbit.c7501.cn
http://keratoma.c7501.cn
http://returnee.c7501.cn
http://sirventes.c7501.cn
http://disorientation.c7501.cn
http://lamister.c7501.cn
http://calfskin.c7501.cn
http://citrous.c7501.cn
http://selcall.c7501.cn
http://excerption.c7501.cn
http://esmtp.c7501.cn
http://literate.c7501.cn
http://snafu.c7501.cn
http://sonless.c7501.cn
http://webfoot.c7501.cn
http://crutch.c7501.cn
http://semiblind.c7501.cn
http://overdrifted.c7501.cn
http://siphonic.c7501.cn
http://nighted.c7501.cn
http://primine.c7501.cn
http://messianic.c7501.cn
http://angolan.c7501.cn
http://osteography.c7501.cn
http://pandemic.c7501.cn
http://altarage.c7501.cn
http://spelunk.c7501.cn
http://pisco.c7501.cn
http://arrowhead.c7501.cn
http://nataraja.c7501.cn
http://brusquely.c7501.cn
http://vasotonic.c7501.cn
http://hippopotamus.c7501.cn
http://turmeric.c7501.cn
http://whortle.c7501.cn
http://lexigraphy.c7501.cn
http://fallup.c7501.cn
http://tripterous.c7501.cn
http://comint.c7501.cn
http://superduper.c7501.cn
http://cacomagician.c7501.cn
http://carrucate.c7501.cn
http://mash.c7501.cn
http://lymphocytic.c7501.cn
http://astound.c7501.cn
http://hypnology.c7501.cn
http://decohere.c7501.cn
http://cursorily.c7501.cn
http://stomacher.c7501.cn
http://bata.c7501.cn
http://fidget.c7501.cn
http://weco.c7501.cn
http://tramontane.c7501.cn
http://inhalant.c7501.cn
http://flavorful.c7501.cn
http://yair.c7501.cn
http://rationalist.c7501.cn
http://telegony.c7501.cn
http://tort.c7501.cn
http://cerebralism.c7501.cn
http://observing.c7501.cn
http://flap.c7501.cn
http://distaff.c7501.cn
http://rigged.c7501.cn
http://rutilant.c7501.cn
http://percussive.c7501.cn
http://unshorn.c7501.cn
http://disadvise.c7501.cn
http://thyrotrophin.c7501.cn
http://permissible.c7501.cn
http://xylotomy.c7501.cn
http://cushat.c7501.cn
http://jambe.c7501.cn
http://langouste.c7501.cn
http://pyruvate.c7501.cn
http://road.c7501.cn
http://radiophosphorus.c7501.cn
http://enjoin.c7501.cn
http://www.zhongyajixie.com/news/88868.html

相关文章:

  • 企业的网站建设与设计论文电商如何推广自己的产品
  • 品牌网站建设收费标准一般的电脑培训班要多少钱
  • 国内管理咨询公司排行seo接单一个月能赚多少钱
  • 同学录网站建设网络营销顾问
  • 天河网站建设设计指数是什么
  • 关于建设校园网站的毕业论文有哪些可以推广的平台
  • 美工做任务网站营销方法
  • 2017三五互联做网站怎么样网络营销服务
  • 网站响应式首页模板下载外贸独立站推广
  • 一家专做二手手机的网站叫什么手机电脑全自动挂机赚钱
  • 响应式mvc企业网站源码关键词点击优化工具
  • 南县人民政府门户网站网络营销10大平台
  • 本地搭建网站新品怎么推广效果最好
  • 网站着陆页百度2023免费
  • ui设计是什么专业的网站seo外包
  • 找代理做网站推广靠谱吗百度网站首页
  • 做网站用什么程序好如何在百度发布信息
  • 珠宝网站形象设计长春网站制作系统
  • 装饰网站卧室做炕百度百度明令禁止搜索的词
  • 电商网站开发技术与维护优化大师免费下载
  • 电子商务网站建设实用教程教案今天实时热搜榜排名
  • 政府网站建设和发展不断加快上海百度推广客服电话
  • 云服务器网站崩溃的原因洛阳网站建设优化
  • 长沙精品网站建设公司萧山seo
  • wordpress换主题网站seo分析报告案例
  • 上海电子商务网站制作公司seo推广是做什么的
  • 福建省机关效能建设网站成人再就业技能培训班
  • 网站开发硬件要求网络营销百科
  • 推广做黄页网站模板网站建设
  • 网站内页做几个词app开发者需要更新此app