Oracle 的一个 MyBatis 查询中有两个删除?

Two delete in one MyBatis query for Oracle?

我想从两个表中删除两行。每一个一行。在 XML 映射器中。
MyBatis executing multiple sql statements in one go, is that possible? 触及该问题,但答案与 XML 映射器无关或 - 看下面 - 不适用于 Oracle。

根据提到的,我需要写:

<delete id="removeReportRecord" >
    DELETE FROM S01_SESTAVA WHERE (id_s01_sestava = #{idReport});
    DELETE FROM S02_DATA WHERE (id_s01_sestava = #{idReport});
</delete >
...
int removeReportRecord(Long idReport);

但这不适用于 Oracle。我试过没有“;”在第三行,或者在两个删除操作上(MyBatis with Oracle 不喜欢结尾“;”)或者在接口中为参数使用注释 - 我总是有相同的消息:

org.apache.ibatis.exceptions.PersistenceException: 
### Error updating database.  Cause: java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended

### The error may involve defaultParameterMap
### The error occurred while setting parameters
### Cause: java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended

如果我改为使用两个后续查询:

<delete id="removeReportRecord" >
    DELETE FROM S01_SESTAVA WHERE (id_s01_sestava = #{idReport})
</delete >
<delete id="removeReportData" >
    DELETE FROM S02_DATA WHERE (id_s01_sestava = #{idReport})
</delete >
...
int removeReportRecord(Long idReport);
int removeReportData(Long idReport);

没问题,一切正常。我已经用 @Transactional 涵盖了这两个操作,它可以工作并且看起来很安全,但是如果我真的需要在一个查询中使用多个 SQL 运算符,我该如何使用这些 MyBatis XML + Oracle?我做错了什么吗?

是否支持执行多条语句取决于驱动。
Oracle 的 JDBC 驱动程序以下列方式支持它(使用 ojdbc8 19.8.0.0 测试)。

<delete id="removeReportRecord">
  BEGIN
    DELETE FROM S01_SESTAVA WHERE (id_s01_sestava = #{idReport});
    DELETE FROM S02_DATA WHERE (id_s01_sestava = #{idReport});
  END;
</delete >

请注意,使用此方法,方法 returns -1 而不是删除的行数,因为驱动程序 returns -1 来自 PreparedStatement#getUpdateCount() .