Is there a way to update a column only when it is null and leave it as it is when it is not null in one multiple-columns-update query?
something like below. (like how we use case in select statements)
UPDATE users SET users.city = 'Dallas',
CASE
WHEN users.Global_id IS NULL
THEN
users.Global_id = '123'
END WHERE userid = '12312312'
The above update statement throws ORA-00927: missing equal sign error.
Reason why I am looking for this?
I have a schedule job that runs a similar query like above.
And there also exists a trigger in users table that will raise error if you try to update a ‘not null’ global_id. So my job fails when it encounters this trigger.
I have one option… to split this update query to two.. one to update city and one to update global_id where global_id is null.
But wondering if this can be achieved by any other way… Any idea would be appreciated.
You can use coalesce function:
Also, you can split your update in two sentences, remember than you can enclose it in a single transaction: