mysql insert or replace_dbinsert

mysql insert or replace_dbinsert通常情况下insert语句的写法为insertintotablenamevalues(a,b);区别之处:1oracle中使用如下语句1.1方式一该方式特点是能插如值是固定的多条数据insertallintotest01values(1,’a’)intotest01values(2,’b’)select1fromdual;–这一行不…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

通常情况下insert语句的写法为 insert into tablename values (a,b);

区别之处:

1oracle中使用如下语句

1.1方式一

该方式特点是能插如值是固定的多条数据
insert all
 
into test01 values(1,’a’)
 
into test01 values(2,’b’)
 
select 1 from dual; –这一行不能去掉

1.2方式二

该方式特点是:能插入一些值不是固定的多条数据.可以吧其他表中的数据批量保存到这张表中来
insert into test01 (id,line1)

       select id,line1 from test02;

1.3方式三

放在begin end里面如下:

begin
insert into test01 (id,line1) values (01,’line01′);
insert into test01 (id,line1) values (01,’line01′);
insert into test01 (id,line1) values (01,’line01′);
insert into test01 (id,line1) values (01,’line01′);
end;

这个可以在Mybatis的sql中优化为

<insert id=”insertRoleInfoList”  parameterType=”java.util.Map”>
 
   <foreach collection=”roleInfoList” item=”userRoleInfo” index=”index” open=”begin” close=”;end;” separator=”;”>
      insert into base_role_demo (roleid,rolecode,roledesc,remark,recordercode,recorderdesc,usecorpcode,usecorpdesc)
      values(ROLEDEMO_CORP_SEQ.Nextval,#{userRoleInfo.rolecode},#{userRoleInfo.roledesc},#{userRoleInfo.remark},
      #{recordercode},#{recorderdesc},#{userRoleInfo.usecorpcode},#{userRoleInfo.usecorpdesc})
    </foreach>
  
  </insert>

2mysql使用如下语句

insert into test01 (id,line1) values (01,’line01′),(02,’line02′);

这种连写的方式可以同时添加多条

接下来说一说关于foreach 语句的区别

主要不同点在于foreach标签内separator属性的设置问题:

  1. separator设置为”,”分割时,最终拼接的代码形式为:insert into table_name (a,b,c) values (v1,v2,v3) ,(v4,v5,v6) ,…
  2. separator设置为”union all”分割时,最终拼接的代码形式为:insert into table_name (a,b,c) values (v1,v2,v3) union all (v4,v5,v6) union all…

oracle中:

<insert id=”inserData” parameterType=”com.test.aaa.Bac”>
    insert into table_name (name, adress, age) values <foreach collection=”list” item=”item” index=”index” separator=”union all”>
            (select #{item.name},
                    #{item.adress},
                    #{item.age}
                from dual   )
        </foreach>
</insert>

MySQL中:

<insert id=”inserData” parameterType=”com.test.aaa.Bac”>
    insert into table_name (name, adress, age)
        values
        <foreach collection=”list” item=”item” index=”index” separator=”,”>
            (   #{item.name},  #{item.adress},  #{item.age}  )
        </foreach>
</insert>

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/193957.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • bookkeeper具体做什么_reading for knowledge翻译

    bookkeeper具体做什么_reading for knowledge翻译序言,关于capCAP是分布式系统中的一个特别重要的理论。CAP原则又称CAP定理,指的是在一个分布式系统中,Consistency(一致性)、Availability(可用性)、Partitiontolerance(分区容错性),三者不可得兼。CAP是NOSQL数据库的基石。分布式系统的CAP理论:理论首先把分布式系统中的三个特性进行了如下归纳:一致性(C):在分布式系统中的所…

    2025年7月7日
    0
  • CSS3 background-size图片自适应

    CSS3 background-size图片自适应

    2021年9月21日
    50
  • SQL insert into select 用法

    SQL insert into select 用法SQLinsertintoselect用法一张存在的表,插入的新数据来源别的表时,可以使用insertintoselect语法。1、两种语法1、表数据user表idnamea

    2022年7月1日
    32
  • 转:三款免费好用的Gif录屏神器

    转:三款免费好用的Gif录屏神器原文链接:三款免费好用的Gif录屏神器自己用了ScreenToGif版本2.14.1下载地址原文内容:三款免费好用的Gif录屏神器2018年06月02日18:52:21独家雨天阅读数:147531.免费开源的GIF录制工具ScreenToGif官网地址:http://www.screentogif.c…

    2022年9月19日
    1
  • SQL中的DECIMAL()函数

    SQL中的DECIMAL()函数&nbsp;&nbsp;&nbsp;&nbsp;Decimal为SQL&nbsp;Server数据类型,属于浮点数类型。一个decimal类型的数据占用了2~17个字节。&nbsp;&nbsp;&nbsp;&nbsp;Decimal&nbsp;数据类型Decimal变量存储为96位(12个字节)无符号的整型形式,&nbsp;&nbsp;&nbsp;&nbsp;D

    2022年7月20日
    16
  • vue子组件调用父组件父页面的方法「建议收藏」

    vue子组件调用父组件父页面的方法「建议收藏」如图:选择城市后,页面重新请求数据!(城市选择是子组件)选择完后不刷新页面,重新调用接口渲染主页面!第一种方法是直接在子组件中通过this.$parent.event来调用父组件的方法父组件<template><div><child></child></div></template&gt…

    2022年10月2日
    5

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号