错误:ORA-30926:无法在源表中获取稳定的行集

时间:2013-11-24 22:13:32

标签: sql plsql

我收到错误:当我运行以下语句时,无法在源表中获得稳定的行集。

   merge into table_1 c
    using (select rep_nbr, T_nbr, SF from table_2) b
    on (c.rep_id=b.rep_nbr)
    when matched then
    update set 
    c.T_ID =b.T_nbr,
    c.SF=b.SF
    when not matched then
    insert(T_id, SF)
    values(null, null);

当我在rep_nbr

之前放置时
merge into table_1 c
    using (select distinct rep_nbr,t_nbr,SF from table_2) b
    on (c.rep_id=b.rep_nbr)
    when matched then
    update set 
    c.T_ID =b.T_nbr,
    c.SF=b.SF
    when not matched then
    insert(T_id, SF)
    values(null, null);

ORA-01400:无法在c.rep_id中插入NULL。 我不想填充c.rep_id,我只需要它们匹配然后更新那些匹配的记录。

2 个答案:

答案 0 :(得分:0)

如果我理解正确,你不需要MERGE,只需要更新。这样的事情应该有效:

UPDATE table_1 t1 
SET t1.t_id = (SELECT DISTINCT t2.t_nbr FROM table_2 t2 WHERE t1.rep_id = t2.rep_nbr),
    t1.sf = (SELECT DISTINCT t2.sf FROM table_2 t2 WHERE t1.rep_id = t2.rep_nbr),
WHERE t1.rep_id IN (SELECT rep_nbr FROM table_2)
但是,但是,在Oracle的后续版本(从10日或11日)中,您可以取出合并的部分内容,例如,取出WHEN NOT MATCHED部分。

答案 1 :(得分:0)

删除部分“与当时不匹配”

merge into table_1 c
    using (select distinct rep_nbr,t_nbr,SF from table_2) b
    on (c.rep_id=b.rep_nbr)
    when matched then
    update set 
    c.T_ID =b.T_nbr,
    c.SF=b.SF