日期:2014-05-17  浏览次数:21171 次

用merge遇到的问题


SQL> merge into book b
  2  using book1 b1
  3  on (b.bookid = b1.bookid)
  4  when matched then
  5   update set b.bookid = 'tp2001--001'
  6  when not matched then
  7   insert values (br.bookid, br.cardid, br.bdate, br.sdate);
merge into book b
           *
第 1 行出现错误:
ORA-00947: 没有足够的值

这是什么问题,神马情况啊

------解决方案--------------------
引用:
改过来了

SQL>  merge into book b
  2   using book1 b1
  3   on(b.bookid = b1.bookid)
  4   when matched then
  5    update set b.bookid = 'tp2001--001'
  6   when not matched then
  7    insert values (b1.bookid, b1.bookname,b1.editor,b1.price,b1.publish,b1.pubdate,b1.qty);
 on(b.bookid = b1.bookid)
    *
第 3 行出现错误:
ORA-38104: 无法更新 ON 子句中引用的列: "B"."BOOKID"
还是有错啊


官方文档说的很清楚了:
http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_9016.htm#SQLRF01606

Restrictions on the merge_update_clause This clause is subject to the following restrictions:
You cannot update a column that is referenced in the ON condition clause.
You cannot specify DEFAULT when updating a view.