使用 HQL 进行条件更新

conditional update using HQL

我正在尝试使用以下运行良好的脚本来更新我的数据库的某些行:

update DOS
set NAMEDOS=:name,
AGEDOS=:age,
WEIGHTDOS=:weight
where CODEDOS=:code

我的问题如下,有时权重可以为空或为空,所以我必须设置其他属性。

我试过这样操作,但似乎行不通:

update DOS
set NAMEDOS=:name,
AGEDOS=:age,
WEIGHTDOS= (case when weight is not null then :weight else :WEIGHTDOS end),
where CODEDOS=:code

你能帮帮我吗

尝试稍微切换括号,我认为 :WEIGHTDOS 应该没有双点,因为它是直接列名而不是参数:

update DOS
    set NAMEDOS=:name,
    AGEDOS=:age,
    WEIGHTDOS= case when (:weight is not null) then :weight 
                  else WEIGHTDOS 
               end,
    where CODEDOS=:code