zoukankan      html  css  js  c++  java
  • mybatis中批量添加orcale

    Oracle数据库批量保存, Oracle不支持values(),(),()


    SQL:

    1、

    begin
    insert into emp(emp_id,name,email) 
    values(1000,'李白','11@11.com');
    insert into emp(emp_id,name,email) 
    values(1001,'李二白','22@22.com');
    end;

    2、

    insert into emp(emp_id,name,email) 
    select emp_id,name,email from(
    select 1000 emp_id ,'李白' name,'11@11.com' email from dual
    union
    select 1001 emp_id ,'李二白' name,'t22@22.com' email from dual
    )    

    xml:

    collection:指定要遍历的集合:
    item:将当前遍历出的元素赋值给指定的变量
    separator:每个元素之间的分隔符
    open:遍历出所有结果拼接一个开始的字符
    close:遍历出所有结果拼接一个结束的字符

    <!-- oracle第一种批量方式 -->
    <insert id="addEmps">
    <foreach collection="emps" item="emp" open="begin" close="end;">
      insert into emp(emp_id,name,email) 
      values(#{emp.emp_id},#{emp.name},#{emp.email});
    </foreach>
    <insert>
    <!-- oracle第二种批量方式 -->
    <insert id="addEmps">
    insert into emp(emp_id,name,email) 
    <foreach collection="emps" item="emp" separator="union" open="select emp_id,name,email from(" close=")">
        select  #{emp.emp_id}  emp_id ,#{emp.name} name,#{emp.email} emai from dual
    </foreach>
    </insert>
  • 相关阅读:
    团队作业第五次——Alpha冲刺
    Alpha冲刺——总结
    冲刺随笔
    冲刺随笔——Day_Nine
    冲刺随笔——Day_Eight
    冲刺随笔——Day_Seven
    冲刺随笔——Day_Three
    团队作业第五次——Alpha冲刺
    第06组 Alpha冲刺(1/6)
    第06组 团队Git现场编程实战
  • 原文地址:https://www.cnblogs.com/tdyang/p/12747703.html
Copyright © 2011-2022 走看看