开发者

selectively update prepared 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜