orcl 日期加减运算
在Oralce中我发现有add_months函数,加天数N可以用如下方法实现,select sysdate+N from dual在Oralce中我发现有add_months函数,加天数N可以用如下方法实现,select sysdate+N from dual ,sysdate+1 加一天
sysdate+1/24 加1小时
sysdate+1/(24*60) 加1分钟
sysdate+1/(24*60*60) 加1秒钟
类推至毫秒0.001秒加法
select sysdate,add_months(sysdate,12) from dual;
select sysdate,add_months(sysdate,1) from dual;
select sysdate,to_char(sysdate+7,'yyyy-mm-dd HH24:MI:SS') from dual;
select sysdate,to_char(sysdate+1,'yyyy-mm-dd HH24:MI:SS') from dual;
select sysdate,to_char(sysdate+1/24,'yyyy-mm-dd HH24:MI:SS') from dual;
select sysdate,to_char(sysdate+1/24/60,'yyyy-mm-dd HH24:MI:SS') from dual;
select sysdate,to_char(sysdate+1/24/60/60,'yyyy-mm-dd HH24:MI:SS') from dual;
减法
select sysdate,add_months(sysdate,-12) from dual;
select sysdate,add_months(sysdate,-1) from dual;
select sysdate,to_char(sysdate-7,'yyyy-mm-dd HH24:MI:SS') from dual;
select sysdate,to_char(sysdate-1,'yyyy-mm-dd HH24:MI:SS') from dual;
select sysdate,to_char(sysdate-1/24,'yyyy-mm-dd HH24:MI:SS') from dual;
select sysdate,to_char(sysdate-1/24/60,'yyyy-mm-dd HH24:MI:SS') from dual;
select sysdate,to_char(sysdate-1/24/60/60,'yyyy-mm-dd HH24:MI:SS') from dual;