码迷,mamicode.com
首页 > 数据库 > 详细

oracle mybatis 批量插入遇到的问题

时间:2015-03-20 17:44:11      阅读:415      评论:0      收藏:0      [点我收藏+]

标签:

1、这是一个很蛋疼的问题,用<insert>的话会一直报sql语法错误,我这里改用<update>测试OK,用<select>貌似也行

2、批量插入带oracle序列递增遇到的错误:java.sql.SQLSyntaxErrorException: ORA-02287: 此处不允许序号

查资料说有很多限制

Restrictions on Sequence Values You cannot use CURRVAL and NEXTVAL in the
following constructs:
■ A subquery in a DELETE, SELECT, or UPDATE statement
■ A query of a view or of a materialized view
■ A SELECT statement with the DISTINCT operator
■ A SELECT statement with a GROUP BY clause or ORDER BY clause
■ A SELECT statement that is combined with another SELECT statement with the
UNION, INTERSECT, or MINUS set operator
■ The WHERE clause of a SELECT statement
■ The DEFAULT value of a column in a CREATE TABLE or ALTER TABLE statement
■ The condition of a CHECK constrain

在mybatis <foreach>外边再套一层解决

    <update id="insertBatch" parameterType="java.util.Map" >
        insert into T_CARD_MAGNETIC_DATA (RECORD_NO, ORDER_NO, ISSUE_ORG_CODE,
        MANUFACTURER_RECORD_NO, CARD_NO, CARD_BIN,
        CARD_TYPE, FIRST_STRIPE, SECOND_STRIPE,
        THIRD_STRIPE, FACE_VALUE, VALID_DATE,
        SERVICE_CODE, CARD_CVN, INIT_PWD,
        CREATE_UID, CREATE_TIME, SYN_FLAG,
        SYN_FROM_TIME, SYN_TO_TIME)
        select seq.nextval,A.* from(
        <foreach collection="cards" item="item" index="index" separator="union all">
            select
            #{cardOrder.orderNo,jdbcType=VARCHAR}, #{cardOrder.issueOrgCode,jdbcType=VARCHAR},
            #{cardOrder.manufacturerRecordNo,jdbcType=DECIMAL}, #{item.cardNo,jdbcType=VARCHAR},
            #{cardOrder.cardBin,jdbcType=VARCHAR},
            #{cardOrder.cardType,jdbcType=VARCHAR}, #{firstStripe,jdbcType=VARCHAR}, #{secondStripe,jdbcType=VARCHAR},
            #{thirdStripe,jdbcType=VARCHAR}, #{cardOrder.faceValue,jdbcType=DECIMAL},
            #{cardOrder.validDate,jdbcType=DATE},
            #{serviceCode,jdbcType=CHAR}, #{cardCvn,jdbcType=CHAR}, #{item.initPwd,jdbcType=VARCHAR},
            #{createUid,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{synFlag,jdbcType=CHAR},
            #{synFromTime,jdbcType=TIMESTAMP}, #{synToTime,jdbcType=TIMESTAMP}
            from dual
        </foreach>
        )A
    </update>

 

oracle mybatis 批量插入遇到的问题

标签:

原文地址:http://www.cnblogs.com/Aurelius/p/4353831.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!