MyBatis executing multiple sql statements in one go, is that possible?

Marco picture Marco · Aug 24, 2011 · Viewed 41.7k times · Source

i was wondering if it is possible to execute multiple sql statements in 1 go. For example the scenario that i want to delete rows from multiple tables, is there a way i can do things like..

<delete id="delete" parameterType="String">
    DELETE FROM DUMMYTABLE_A where X=${value}
    DELETE FROM DUMMYTABLE_B where X=${value}
</delete>

Answer

StrekoZ picture StrekoZ · Dec 1, 2011

I'm using myBatis with Oracle. I guess there is something similar in other DB. Actually you always can create procedures in DB, which usually is better for the future, when you have to support the project.

<delete id="deleteUnfinishedData" parameterType="map">
    {call
        declare
        begin
            delete from TABLE1 where id = #{valueFromMap1};
            delete from TABLE2 where id = #{valueFromMap2};
        end
    }
</delete>