如 表ss 字段有 id bengtime endtime,我要根据id更新,若bengtime为空则更新bengtime,否则更新endtime
oracleä¸æ¡ä»¶æ´æ°ç¨case whenç»æï¼ä¸¾ä¾å¦ä¸ï¼
ç¨æ³å¦ä¸ï¼
update test set column1=
(case testCond
when ' ' then 'xxx'
else yyy end )
è¿æ ·å°±å¯ä»¥æ´å ·æ个å段çå¼æ¥æ´æ°å¦å¤ä¸ä¸ªå段äºã
ç¨æ³å¦ä¸ï¼
update test set column1=
(case testCond
when ' ' then 'xxx'
else yyy end )
è¿æ ·å°±å¯ä»¥æ´å ·æ个å段çå¼æ¥æ´æ°å¦å¤ä¸ä¸ªå段äºã
温馨提示:答案为网友推荐,仅供参考
第1个回答 推荐于2018-03-12
通用sql:
update ss
set bengtime = case when bengtime is null then sysdate else bengtime end,
endtime = case when endtime is null then sysdate else endtime end
where id = ...
或者,简单点:
update ss
set bengtime = nvl(bengtime,sysdate),
endtime =nvl(endtime,sysdate)
where id = ...
update ss
set bengtime = case when bengtime is null then sysdate else bengtime end,
endtime = case when endtime is null then sysdate else endtime end
where id = ...
或者,简单点:
update ss
set bengtime = nvl(bengtime,sysdate),
endtime =nvl(endtime,sysdate)
where id = ...
第2个回答 2012-12-05
update ss set bengtime=decode(bengtime ,null,sysdate-1,bengtime),endtime=decode(bengtime,null,endtime,sysdate) where id=xxxxx;本回答被提问者和网友采纳