有两张表 A B id hyid hyid newid 1 2 2 A 2 3 3 B 现在要将a表的hyid换成b表的newid,请注意a表中的hyid不是唯一的 oracle中该 怎么处理
merge into a using b on (a.hyid=b.hyid) when matched then update set a.hyid=b.newid a.hyid 在on句中,不能修改
我另外在a表中弄了一条数据hy和hyid保持一致 并且因为a表中的hyid不是唯一的,结果错误无法获得稳定行update a set hyid=( select newid from b where hyid=a.hyid) where exists( select 1 from b where hyid=a.hyid) SQL code: update a set a.hyid=(select newid from b where b.hyid=a.hyid and rownum<2) and exists (select 1 from b where b.hyid=a.hyid);
1楼正解,用merge无法修改 看样子不错 ,不过还是修改不了,错误:单行子查询返回多个行
--where rownum=1限制下
update a set hyid=( select newid from b where hyid=a.hyid where rownum=1) where exists( select 1 from b w