zoukankan      html  css  js  c++  java
  • 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了。

  • 相关阅读:
    九度oj 题目1051:数字阶梯求和
    九度oj 题目1472:求两个多项式的和
    九度oj 题目1173:查找
    九度oj 题目1447:最短路
    九度oj 题目1104:整除问题
    [Luogu] 维护序列
    [Luogu] 计算系数
    [Luogu] 聪明的质监员
    [Luogu] Mayan游戏
    [Luogu] 选择客栈
  • 原文地址:https://www.cnblogs.com/wuxun1997/p/6602202.html
Copyright © 2011-2022 走看看