开发者

selectively update prepared statement

开发者 https://www.devze.com 2022-12-25 23:20 出处:网络
for an prepared statement update table t set a = ? ,b = ? where i = ? column a to stay column a ie. a=a and only开发者_开发问答 need to setInt for b and visa versa, without needing another statement

for an prepared statement

update table t set a = ? ,b = ? where i = ?

column a to stay column a ie. a=a and only开发者_开发问答 need to setInt for b and visa versa, without needing another statement. Is there a concise way of doing this?


You could try this:

UPDATE TableT
SET a = COALESCE(?, a),
    b = COALESCE(?, b)
WHERE i = ?

To leave a value unchanged, simply pass NULL in. Of course you cannot use this method if you actually wish to set the value to NULL.

0

精彩评论

暂无评论...
验证码 换一张
取 消