上記のスレッドでMichaelSが提供する回答は正常に機能するはずです。受け取ったエラー メッセージ (ORA-38104: ON 句で参照されている列を更新できません: foo.id) は、次のようなことをしようとしていることを示しています。
merge into foo
using (select null from dual)
on (foo.id = bar.id)
when matched then update set foo.id = bar.id, foo.another_field = bar.another_field
when not matched then insert VALUES bar;
エラーが示すように、「ON」句で参照される列は更新できません。そのため、次のようにするとうまくいきます。
merge into foo
using (select null from dual)
on (foo.id = bar.id)
when matched then update set foo.another_field = bar.another_field
when not matched then insert VALUES bar;
本当に foo.id を更新する必要がある場合は、次の解決策が考えられます:マージ時に ORA-3814 エラーを回避するには?
編集
考えられる代替手段は、次のようにすることです。
update foo set row = bar where foo.id = bar.id;
if sql%rowcount = 0 then
insert into foo values bar;
end if;
これは基本的に、merge ステートメントと同じことを行うことと同じです。