Mybatis中xml批量执行Oracle的Sql必须加上 BEGIN END;

<insert id="insertOrUpdateBatch" parameterType="java.util.List" useGeneratedKeys="false">
        BEGIN
        <foreach collection='list' item='item' separator=';'>
            MERGE INTO T_WARNING_VALUE t1 USING
            (
            SELECT
            #{item.indexId} INDEX_ID,
            #{item.indexTime} INDEX_TIME,
            #{item.indexValue} INDEX_VALUE,
            #{item.indexDate} INDEX_DATE,
            #{item.dataType} DATA_TYPE,
            #{item.areaId} AREA_ID
            FROM DUAL
            )  t2
            ON
            (t1.INDEX_ID = t2.INDEX_ID and t1.INDEX_TIME= t2.INDEX_TIME
            and t1.DATA_TYPE = t2.DATA_TYPE and t1.AREA_ID = t2.AREA_ID)
            WHEN MATCHED THEN
            UPDATE SET  t1.INDEX_VALUE = t2.INDEX_VALUE
            WHEN NOT MATCHED THEN
            INSERT (INDEX_ID, INDEX_TIME, INDEX_VALUE,INDEX_DATE,DATA_TYPE,AREA_ID)
            VALUES (t2.INDEX_ID, t2.INDEX_TIME, t2.INDEX_VALUE,t2.INDEX_DATE,t2.DATA_TYPE,t2.AREA_ID)
        </foreach>;
        END;
    </insert>

上一篇:根据Collect集合中对象的某个属性对list排序


下一篇:Mysql汇总