rbrooker
Member³
Hi,
found these the other day, thought someone out there could make use of them.
have a nice day 
found these the other day, thought someone out there could make use of them.
Code:
-- this week
SELECT decode(TRIM(to_char(SYSDATE, 'DAY')),
'SUNDAY', next_day(trunc(SYSDATE - 6), 'SUNDAY'),
next_day(trunc(SYSDATE - 8), 'SUNDAY')) - 1 + LEVEL
FROM dual
CONNECT BY LEVEL <= 7;
Code:
-- last 7 days
SELECT trunc(SYSDATE) - 7 + LEVEL
FROM dual
CONNECT BY LEVEL <= 7;
Code:
-- this month
SELECT to_date(to_char(SYSDATE, 'yyyy'), 'yyyy') - 1 + LEVEL
FROM dual
CONNECT BY LEVEL <= to_char(last_day(SYSDATE), 'dd');
Code:
-- last 30 days
SELECT trunc(SYSDATE) - 30 + LEVEL dateparam
FROM dual
CONNECT BY LEVEL <= 30;
Code:
-- month to date
SELECT to_date(to_char(SYSDATE, 'yyyy'), 'yyyy') - 1 + LEVEL
FROM dual
CONNECT BY LEVEL <= to_char(SYSDATE, 'dd');
Code:
-- this year
SELECT to_date('0101' || to_char(SYSDATE, 'yyyy'), 'ddmmyyyy') - 1 + LEVEL
FROM dual
CONNECT BY LEVEL <= 365;
Code:
-- last 365 days
SELECT trunc(SYSDATE) - 365 + LEVEL dateparam
FROM dual
CONNECT BY LEVEL <= 365;
Code:
-- year to date
SELECT to_date('0101' || to_char(SYSDATE, 'yyyy'), 'ddmmyyyy') - 1 + LEVEL
FROM dual
CONNECT BY LEVEL <= to_char(SYSDATE, 'ddd');
