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

  • 相关阅读:
    Nginx下载服务器配置文件
    php7连接mysql测试代码
    Vagrant 构建 Linux 开发环境
    清理buffer/cache/swap的方法梳理
    【12】
    python全栈目录
    Chrome启动后打开第一个网页很慢的解决方案
    Pycharm快捷键
    TEst
    1、Linux命令随笔
  • 原文地址:https://www.cnblogs.com/wuxun1997/p/6602202.html
Copyright © 2011-2022 走看看