orcale+mybatis實現多條sql執行
阿新 • • 發佈:2020-02-27
先上程式碼:
<insert id="copyinsertBatch" parameterType="java.util.List" useGeneratedKeys="false" > begin insert into CEB_DEPARTURE_HEAD_HIS <foreach item="item" collection="dataList" separator=" UNION ALL " index="index" > <if test="index != 0"> <choose> <when test="index % 1000 ==999">; insert into CEB_DEPARTURE_HEAD_HIS </when> </choose> </if> select * from CEB_DEPARTURE_HEAD where ID = #{item} </foreach>; insert into CEB_DEPARTURE_LIST_HIS <foreach item="item" collection="dataList" separator=" UNION ALL " index="index" > <if test="index != 0"> <choose> <when test="index % 1000 ==999">; insert into CEB_DEPARTURE_LIST_HIS </when> </choose> </if> select * from CEB_DEPARTURE_LIST where ID = #{item} </foreach>; end; </insert>
重點:必須用 begin end; 把多條sql語句 拼再一起,每個sql 用分號“;”隔開;
begin
sql1;
sql2;
end;
弊端:沒有返回執行量