Oracle 联合表更新某一个表的字段
背景:要把ORGAN.orgName字段 赋值到SYNRECORD.BUSINESSNAME字段,如下:
首先,我们要找到关联的表,想办法把他们串联起来。最后要判断这个条件存在才进行更新。
update SYNRECORD d set d.BUSINESSNAME =(select c.orgName from RECORD a, ORGAN c where c.Userid = a.Applyuserid and a.dealnumber = d.businessid)
where exists (select 1 from GPRECORD a, SOORGAN c where c.Userid = a.Applyuserid and a.dealnumber = d.businessid) and d.BUSINESSNAME like '%?%'
其中 RECORD.dealNumber = synrecord.businessid, ORGAN.userid= RECORD.APPLYUSERID
判断某字段是否为null,判断是否为字符和数字时的写法不一样。当为数字时,
CASE WHEN columnName is null THEN 0 ELSE columnName END