天天看點

Mybatis内批量插入Oracle

<insert id="insertManagerInfoBatch" parameterType="java.util.List">
        <selectKey resultType="java.math.BigDecimal" order="BEFORE" keyProperty="id">
            SELECT XSHTEST.XSHE_BRANCH_OFFICE_SEQ.Nextval as ID from DUAL
        </selectKey>
        insert into xshtest.XSHE_CUSTOMER_MANAGER
        (id,manager_name,manager_no,branch_company_id,contact_phone,status)
        SELECT XSHTEST.XSHE_BRANCH_OFFICE_SEQ.Nextval ,t.* FROM (
        <foreach collection="list" item="item" separator="UNION ALL">
            select
            #{item.managerName},
            #{item.managerNo},
            #{item.companyId},
            #{item.contactPhone},
            #{item.status}
            from dual
        </foreach>
        )t
    </insert>      
/**
 *mapper傳參為list
 **/
 int insertManagerInfoBatch(List list);      

不要忘記對序列賦權:grant select on XSHE_BRANCH_OFFICE_SEQ to user

Mybatis内批量插入Oracle