search

Home  >  Q&A  >  body text

oracle 批量插入数据

比如有10条数据。
是用for循环在程序里面一条一条地调用insert,还是其他方法?
还有,for循环能保证事务么?

高洛峰高洛峰3077 days ago658

reply all(1)I'll reply

  • 三叔

    三叔2016-11-03 11:37:26

    贴一个MyBatis中的使用方法

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    <insert id="batchinsert"parametertype="java.util.list"

        INSERT INTO data (id, text, status) 

        <foreach close=")"collection="list"item="item"index="index"open="("separator="union"

            SELECT

                #{item.id,jdbcType=VARCHAR},

                #{item.text,jdbcType=VARCHAR},

                #{item.stauts,jdbcType=VARCHAR}

            FROM DUAL 

         

    </foreach close=")"collection="list"item="item"index="index"open="("separator="union"></insert id="batchinsert"parametertype="java.util.list">


    reply
    0
  • Cancelreply