先创建一个table
create table t_date(
id number,
d1 date,
d2 timestamp
);
select id, d1,d2 from t_date;
select d1 ,add_months(d1,1),last_day(d1) from t_date; --加一个月
select d1 ,last_day(d1) from t_date; --当月的最后一天
select d1 ,trunc(d1) from t_date; --当日,只显示年月日,时间没了
select d1 ,to_char(trunc(d1),'yyyy-mm-dd') from t_date; --当日,字符串显示
select d1 ,trunc(d1,'hh') from t_date; --当日带小时,分秒没了
select d1 ,trunc(d1,'mi') from t_date; --当日带小时,分钟,秒没了
select d1 ,trunc(d1,'mm') from t_date; --当月第一天
select d1 ,trunc(d1,'yyyy') from t_date; --当年的第一天
select d1 ,add_months(trunc(d1,'yyyy'),12)-1 from t_date; --当年的最后一天
select d1 ,trunc(d1,'yyyy')-1 from t_date; --去年的最后一天
select d1 ,add_months(trunc(d1,'yyyy'),12)-0.00001 from t_date; --当年的最后一天最后一秒
select d1 ,trunc(d1,'q') from t_date; --当前所在季度的第一天
select d1, add_months(trunc(d1,'q'),3)-1 from t_date; --当前所在季度的最后一天
select d1 ,trunc(d1,'d') from t_date; --当前所在星期的第一天
select d1 ,next_day(d1,1) from t_date; --下一个周日
select d1 ,next_day(d1,4) from t_date; --下一个周三
select d1 ,next_day(d1,7) from t_date; --下一个周六