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来解决批量新增的问题?

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器