解决Oracle + Mybatis,在mapper.xml中一个标签里写多条SQL语句问题

解决Oracle || MySQL + Mybatis,在mapper.xml中一个标签里写多条SQL语句问题

Oracle
eg.
// 在SQL语句前后分别加BEGIN 和END;(PS:注意END后要加分号“;”),同时在每条SQL语句后用分号“;”隔开。

<update id="updateClass">
        BEGIN
        UPDATE CLASS SET CODE_CLASS = #{code.codeClassName},CODE_CLASS_ID = #{code.codeClassId} WHERE id = #{code.id};
        UPDATE CODE SET CODE_CLASS=#{code.codeClassName} WHERE CODE_CLASS=#{oldClassName};
        END;
</update>
    

MySQL
eg.
1.修改MySQL数据库连接参数加上“allowMultiQueries=true”,即:

url=jdbc:mysql://xx.xx.xx:3306/xxxxx
?characterEncoding=utf8
&autoReconnect=true
&failOverReadOnly=false
&allowMultiQueries=true

2.直接写多条SQL语句,用分号“;”隔开就行了

<delete id="delete">
  delete from A where id = #{id};
  delete from A where age = #{age};
  delete from A where name = #{name};
</delete>

你可能感兴趣的:(编码,SQL)