合并-不在目标表中插入记录

时间:2018-11-01 09:12:33

标签: sql-merge

在执行上述SQL之后,将显示0 Record Merged。 想知道为什么记录未插入表中吗?

表中没有bic = 'WLDSGB40XXX'的记录:

merge INTO BANK_DATA D
USING (SELECT * 
   FROM   BANK_DATA 
   WHERE  bic = 'WLDSGB40XXX') s 
ON (D.bic = s.bic) 
WHEN matched THEN 
  UPDATE SET D.name = 'LONDON',
   D.bank_name =  ' SERVICES LIMITED', 
   D.address = 'ONE OLIVERS YARD', 
   D.city = 'LONDON',
   D.country =  'GB'  
   WHERE (d.bic = 'WLDSGB40XXX' ) 
WHEN NOT MATCHED THEN 
  INSERT (d.ID, d.TYPE,  d.NAME, d.bank_name,  d.address,  d.city,  d.country, d.bic)
  VALUES ((SELECT MAX(to_number(id)) + 1 FROM   BANK_DATA),
  '01', 
  'LONDON',
  'LIMITED', 
  'ONE YARD', 
  '1', 
  '1', 
  'GB40XXX'
  );

0 个答案:

没有答案