oracle 时间的相关操作(随笔)

1、查询当前时间

select sysdate from DUAL;

2、时间转换

select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from DUAL;
select to_date('2019-10-10 10:10:10','yyyy-mm-dd hh24:mi:ss') from DUAL;

3、查询当前时间的前一年

select add_months(sysdate,-12) from DUAL;

4、查询当前时间前一个

select add_months(sysdate,-1) from DUAL;

5、查询当前时间前一秒钟

select sysdate - 1/60/60/24 from DUAL;

 6、查询当前时间前一分钟

 select sysdate - 1/60/24 from DUAL;

7、查询当前时间前一个小时

 select sysdate - 1/24 from DUAL;

8、查询当前时间的前一天

select sysdate - 1 from DUAL;

9、获取当前时间前一年前一个月前一天前一小时前一分钟前一秒

select add_months(add_months(sysdate - 1 - 1 / 24 - 1 / 24 / 60 - 1 / 24 / 60 / 60, -1), -12) from DUAL;

猜你喜欢

转载自blog.csdn.net/qq_38428623/article/details/102584488