当前日期为2018/08/12。
1、获取当前月份的天数:
select to_number(to_char(last_day(sysdate),‘dd‘)) from dual
2、获取当前日期前30天的全部日期。
select trunc(sysdate-30)+rownum as days from dual connect by rownum<=30;
执行结果如下:
2.获取当前日期前一个月的全部日期。此处的一个月会根据当前月份获取本月的天数,可能是31天、30天或者29天。
select trunc(sysdate-to_number(to_char(last_day(sysdate),‘dd‘)))+rownum as days from dual connect by rownum<=to_number(to_char(last_day(sysdate),‘dd‘))
执行结果如下:
4、获取当前日前一周时间(包含当前日期)。
select trunc(sysdate-7)+rownum as days from dual connect by rownum<=7
5、获取当前日前一周时间(不包含当前日期)。
select trunc(sysdate-8)+rownum as days from dual connect by rownum<=7
或者
select trunc(sysdate-7)+rownum-1 as days from dual connect by rownum<=7
执行结果如下:
6、获取从10开始连续10个数字
select 10+rownum as days from dual connect by rownum<=10;
原文地址:https://www.cnblogs.com/xianfengzhike/p/9461937.html
时间: 2024-10-11 10:52:17