如果存在特定的ID,我的查詢會更新一個表,否則它會插入一個新值。在數據庫查詢中設置標誌值
我想要實現像 - :
if(exists){
update table,
flag = 0}
else{
insert into table,
flag = 1}
return flag;
我現有的查詢是
BEGIN
merge into FCM_DEVICE_REGISTRATION u
using dual
on (device_ad_id = 1)
when matched then
update set fcm_notification_id='N',
last_update_date = SYSDATE
when not matched then
insert (device_ad_id,fcm_notification_id) values (1,'Y');
END;
您是否正在使用'INSERT INTO ... ON DUPLICATE KEY UPDATE'? –
什麼是你使用的數據庫引擎? –
@LelioFaieta oracle 12g –