2016-08-01 100 views
0

我試圖運行下面的查詢,但我不斷收到回:UPDATE WHERE在MERGE

Error code 30000, SQL state 42X01: Syntax error: Encountered "WHERE" at line 5, column 38. 

MERGE INTO FOO 
USING BAR 
ON FOO."NAME" = BAR."NAME" 
WHEN MATCHED THEN 
    UPDATE SET FOO."NAME" = 'qwerty' WHERE FOO."AGE" > 30 
WHEN NOT MATCHED THEN 
    INSERT (guid) values('qwerty') 

如果我刪除WHERE FOO."AGE" > 30的話,好像是罰款,但。是否可以在MERGEUPDATE中指定WHERE子句?

我使用的是最新的Apache Derby嵌入式數據庫版本,10.12.1.1

+0

是的,好像[mergeUpdate](https://db.apache.org/ derby/docs/10.12/ref/rrefsqljmerge.html#rrefsqljmerge__mergeupdate)根本不允許使用WHERE子句。但是Phritzy的答案應該如下。 –

回答

0

你可以試試這個:

MERGE INTO FOO 
USING BAR 
ON FOO."NAME" = BAR."NAME" 
AND FOO."AGE" > 30 
WHEN MATCHED THEN 
    UPDATE SET FOO."NAME" = 'qwerty' 
WHEN NOT MATCHED THEN 
    INSERT (guid) values('qwerty')