Meger语句在特定情况下,会抛出“ORA-08006 specified row no longer exists” exception以下SQL,可以使exception再现。
CREATE TABLE SOURCE_test
AS
SELECT object_id, object_name, object_type
FROM all_objects
WHERE OBJECT_name NOT LIKE '%$%' AND object_name NOT LIKE '%#%';
INSERT INTO source_test
SELECT object_id, object_name, object_type
FROM source_test;
INSERT一句,使source_test中,同一个object_id和object_name,有两条数据。
CREATE TABLE target_test
AS
SELECT object_id, object_name, object_type
FROM all_objects
WHERE object_id < 5000
AND OBJECT_name NOT LIKE '%$%' AND object_name NOT LIKE '%#%';
INSERT INTO target_test
SELECT object_id, object_name, object_type
FROM target_test;MERGE INTO target_test t
USING source_test s
ON (s.object_id = t.object_id AND s.object_name = t.object_name)
when matched then update set t.object_type = s.object_type
DELETE WHERE (s.object_id = t.object_id AND s.object_name = t.object_name);oracle的文档中,有关于ORA-08006这种情况的说明吗?

解决方案 »

  1.   

    ORA-08006: specified row no longer exists 
    Cause: the row has been deleted by another user since the operation began
     
    Action: re-try the operation
     
      

  2.   

    如果是bug的话,我在10g和11g都抛exception
    Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Production
    Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production所以我猜测oracle认为不是bug。
      

  3.   

    merge要求source_test与target_test的关系不能是多对多,明显上面的sql没有满足这个条件,因为source_test的object_id+object_name是不唯一的。
      

  4.   

    5楼应该是正解,on里面的条件必须是唯一的。楼主可以尝试一下三种场景:
    1.两句insert都不执行
    2.执行source_test的insert,不执行另外一个
    3.执行target_test的insert,不执行另外一个除了8006,还有可能是30926之类的错误。
      

  5.   


    加上 when not matched thenMERGE INTO target_test t
    USING source_test s
    ON (s.object_id = t.object_id AND s.object_name = t.object_name)
    when matched then update set t.object_type = s.object_type
    when not matched then DELETE WHERE (s.object_id = t.object_id AND s.object_name = t.object_name);