How can I use oracle merge statement using Mybatis?

11,834

Solution 1

Call the merge as below:-

<update id="exceMerge" parameterType="hashmap">
        MERGE INTO USERS U USING DUAL ON (U.PROPERTY_NAME=#{prop_name}) 
        WHEN MATCHED THEN 
        UPDATE SET U.PROPERTYVALUE=#{prop_value}, U.MESSAGE=#{message,javaType=String,jdbcType=CLOB}
        WHEN NOT MATCHED THEN 
        INSERT(PROPERTY_NAME, PROPERTYVALUE, MESSAGE) VALUES (#{prop_name},#{prop_value},#{message,javaType=String,jdbcType=CLOB})
</update>

Solution 2

I'd suggest using a stored procedure, although you may also try just pasting your code into <update> tag.

Calling stored procedures in MyBatis is easy, after you define a procedure in your DB simply follow this example.

Note that in case where your procedure doesn't return any parameters, the procedure call should be in <update> tag (instead of <select>, as in example).

Share:
11,834
MukeshKoshyM
Author by

MukeshKoshyM

Good code is its own best documentation. As you’re about to add a comment, ask yourself, ‘How can I improve the code so that this comment isn't needed?’ Improve the code and then document it to make it even clearer. --Steve McConnell

Updated on June 04, 2022

Comments

  • MukeshKoshyM
    MukeshKoshyM almost 2 years

    I couldn't see any mapper(mybatis-3-mapper.dtd) where I can call a merge statement in mybatis.

    I saw tags for update, insert, delete and SQL

    Anyone please suggest how to use oracle merge statement in Mybatis.