oracle batch import sql statement

https://blog.csdn.net/gnail_oug/article/details/80005957

Due to the need to convert the mysql database to oracle, the batch inserts multiple values ​​of mysql in the mapping file of mybatis, but after changing to the oracle library, sql reports an error. So. Oracle does not support this method of inserting into multiple values

mysql:INSERT INTO users(name, age) VALUES(‘ccc’, 333), (‘aaa’, 222), (‘bbb’, 111);

It turns out that inserting multiple pieces of data with one sql of mysql is not applicable in oracle.

insert into bill.TB_1174253740908220416(BILL_ID,ACCOUNT_BODY)
select SEQ_DEAL_FLOW.nextval,A.* from ( 
  SELECT  '李春英1' from dual  
  UNION
  SELECT  '李春英2' from dual 
  UNION
  SELECT  '李春英3' from dual 
) A

How to write mybatis (in case of sequence)

<!-- 批量插入 --> 
   <insert id="inserts" parameterType="java.util.List"> 
      insert into PRESON 
       select SEQ_PRESON_ID.NEXTVAL,A.* from( 
       <foreach collection="list" item="item" index="index" 
           separator="UNION"> 
           SELECT 
           #{item.presonName}, 
           #{item.presonTel}, 
           #{item.presonEmail}, 
           #{item.presonAge} 
           from dual 
            </foreach> 
       ) A 
   </insert>

Without sequence

https://www.jianshu.com/p/fdba0e023db8

<insert id="insertuser" parameterType="java.util.List" useGeneratedKeys="false" >
    insert into user
    (
        username,
        sex,
        age
    )
    <foreach close=")" collection="list" item="item" index="index" open="(" separator="union all">
        select
            #{item.username},
            #{item.sex},
            #{item.age}
        from dual 
    </foreach>
</insert>

The first kind of insertion

insert into bill.TB_1174253740908220416(BILL_ID,ACCOUNT_BODY)
select 1,'李春英1' from dual
union
select 2,'李春英2' from dual

The second insert statement

INSERT all 
INTO bill.TB_1174253740908220416 (BILL_ID,ACCOUNT_BODY) VALUES(1,'李春英') 
INTO bill.TB_1174253740908220416 (BILL_ID,ACCOUNT_BODY) VALUES(2,'李春英')
SELECT 1 FROM dual;
Published 281 original articles · 50 praises · 450,000 views +

Guess you like

Origin blog.csdn.net/lzh657083979/article/details/104759919