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了。

  • 相关阅读:
    C
    B
    A
    G
    BZOJ_1208_&_Codevs_1258_[HNOI2004]_宠物收养所_(平衡树/set)
    Codevs_1230_元素查找_(set/Hash)
    POJ_2503_Babelfish_(Trie/map)
    POJ_2001_Shortest_Prefixes_(Trie)
    BZOJ_3670_[NOI2014]_动物园_(kmp)
    BZOJ_3196_二逼平衡树_(树套树,线段树+Treap)
  • 原文地址:https://www.cnblogs.com/wuxun1997/p/6602202.html
Copyright © 2011-2022 走看看