兩個不同的用戶,但是表結構相同,已經建設好同義詞,現在進行表結構同步,但是同步的表 MainRelation 中又有些欄位為空,所以想在 matched then update時做個判斷,若MainRelation表有欄位為空,則不同步。下面insert中的表結構就是兩個表的所有欄位結構,現在卡在執行時提示 set if這里,提示缺少 =號,麻煩大神指導,感謝感謝。
merge into relation@TB b
using MainRelation c
on (b.ejycode = c.ejycode)
when matched then
update
set if (c.lecode <>'' and c.lecode is not null) then b.lecode = c.lecode,
if (c.lename <> '' and c.lename is not null) then b.lename := c.lename,
if (c.created_date <> '' and c.created_date is not null) then b.created_date := c.created_date,
if (c.update_date <> '' and c.update_date is not null) then b.updated_date := c.update_date,
if (c.flag <> '' and c.flag is not null) then b.flag = c.flag
when not matched then
insert
values
(c.ejycode,
c.lecode,
c.lename,
c.created_date,
c.update_date,
c.flag);
uj5u.com熱心網友回復:
set if (c.lecode <>'' and c.lecode is not null) then b.lecode = c.lecode,
-- 改成這個試試,條件成立,更新為新值,不成立,則更新來原來的值(間接達到不更新的目的—)
set b.lecode = case when c.lecode <>'' and c.lecode is not null then c.lecode else b.lecode end
uj5u.com熱心網友回復:
updateset if (c.lecode <>'' and c.lecode is not null) then b.lecode = c.lecode
改寫成
update
set n b.lecode =decode(c.lecode,'',b.lecode ,c.lecode)
uj5u.com熱心網友回復:
修正一下,多一個N
update
set if (c.lecode <>'' and c.lecode is not null) then b.lecode = c.lecode
改寫成
update
set b.lecode =decode(c.lecode,'',b.lecode ,c.lecode
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/115037.html
標籤:開發
