如何使用 Mybatis 使用 oracle 合并语句?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19593785/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I use oracle merge statement using Mybatis?
提问by MukeshKoshyM
I couldn't see any mapper(mybatis-3-mapper.dtd) where I can call a merge statement in mybatis.
我看不到任何可以在 mybatis 中调用合并语句的映射器(mybatis-3-mapper.dtd)。
I saw tags for update, insert, delete and SQL
我看到了更新、插入、删除和 SQL 的标签
Anyone please suggest how to use oracle merge statement in Mybatis.
任何人请建议如何在Mybatis中使用oracle合并语句。
回答by Dinesh Sachdev 108
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>
回答by Micha? Rybak
I'd suggest using a stored procedure, although you may also try just pasting your code into <update>
tag.
我建议使用存储过程,尽管您也可以尝试将代码粘贴到<update>
标签中。
Calling stored procedures in MyBatis is easy, after you define a procedure in your DB simply follow this example.
在 MyBatis 中调用存储过程很容易,在你的数据库中定义一个过程后,只需按照这个例子。
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).
请注意,如果您的过程不返回任何参数,则过程调用应在<update>
标记中(而不是<select>
,如示例中所示)。