Mr_SongAS 2014-11-21 09:10 采纳率: 50%
浏览 9569

mybatis加oracle批量insert中的序列问题,可不可以用union做批量的sql语句--急

<insert id="saveManyPopInfo" parameterType="java.util.List">
    insert into popinfo (popid,popname,remark)
    select seq_popid.nextval,p.* from (
    <foreach collection="list" item="pop" separator="union all">
        select #{pop.popname},#{pop.remark} from dual
    </foreach>
    ) p
</insert>
该代码可以实现批量新增的问题,但是我希望用的是union all的方法,即:
<insert id="saveManyPopInfo" parameterType="java.util.List">
           <!--这里的selectKey 感觉只是执行了一次,因为会报一个叫插入重复的错误-->
    <selectKey keyProperty="p1" order="BEFORE" resultType="int">
        select seq_popid.nextval from dual
    </selectKey>
    insert into popinfo (popid,popname,remark)
    <foreach collection="list" item="pop" separator="union all">
        select #{p1},#{pop.popname},#{pop.remark} from dual
    </foreach>
</insert>
    怎么可以用union all来解决批量新增的问题?
  • 写回答

5条回答 默认 最新

  • Mr_SongAS 2014-11-21 09:11
    关注


    <!--这里的selectKey 感觉只是执行了一次,因为会报一个叫插入重复的错误-->

    select seq_popid.nextval from dual

    insert into popinfo (popid,popname,remark)

    select #{p1},#{pop.popname},#{pop.remark} from dual


    怎么可以用union all来解决批量新增的问题?

    评论

报告相同问题?

悬赏问题

  • ¥20 fluent无法启动
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题
  • ¥50 Oracle Kubernetes服务器集群主节点无法访问,工作节点可以访问
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架
  • ¥15 有关sql server business intellige安装,包括SSDT、SSMS。