merge into报错ORA-00926、ORA-38014


  今天用ibatis写个插入操作,为了兼容修改想使用 merge into语句,以便重复插入时直接 update,具体语句如下:

<insert id="wlf">

MERGE INTO t_wlf_info t USING dual ON(t. id=#id# and t.channel=#channel#)

WHEN MATCHED THEN UPDATE SET t.id=#id#,t.channel=#channel#,t.url=#url#

WHEN NOT MATCHED THEN INSERT t_wlf_info

(id,channel, url) VALUES(#id#,#channel#,#url#)

</insert>

  结果遇到了两个问题:

1、java.sql.BatchUpdateException:ORA-00926: missing VALUES keyword

...

2、java. sql.BatchUpdateException: ORA-38104: Columns referenced in the ON Clause cannot be updated: "T"."ID"

...

  第一个问题是在插入时多加了表明,在INSERT后面把表名去掉就好,另外提一点,update和insert后面都不需要加表明的,另外insert后面也不用加INTO,merge into的语法就是这样的。第二个问题是不能把ON后面的条件字段放到update里,它认为你拿id和channel做条件来判断是插入还是修改,如果匹配那么id和channel已经是相应的值了,就没去修改了,举例id=3 and channel=12345678时我去update,否则insert,那么匹配update时被修改的数据已经是id为3、channel为12345678了,这两个字段就不用update了。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM