select to_char(days, 'fmMon ddth'||' - '||'fmmm/dd/yyyy') days
from
(select sysdate + level as days
from dual
connect by level <= to_date ('09/30/2008', 'mm/dd/yyyy') - sysdate)
where extract(day from days) in (1, 15)
/
DAYS
---------------------
Jun 15th - 06/15/2008
Jul 1st - 07/01/2008
Jul 15th - 07/15/2008
Aug 1st - 08/01/2008
Aug 15th - 08/15/2008
Sep 1st - 09/01/2008
Sep 15th - 09/15/2008
SQL> SELECT TO_CHAR(TO_DATE('1900-01-01', 'YYYY-MM-dd'), 'dth')
2 FROM DUAL
3 /
TO_
---
2nd
SQL> select ADD_MONTHS(trunc(sysdate,'YEAR'),12)-1 from dual
2 /
ADD_MONTH
---------
31-DEC-19
SQL> select trunc(to_date('18-sep-2006','dd-mon-yyyy'),'year') from dual;
TRUNC(TO_
---------
01-JAN-06
SQL> SELECT round(sysdate,'YYYY'),add_months(trunc(sysdate,'YYYY')-1,12) from dual
2 /
ROUND(SYS ADD_MONTH
--------- ---------
01-JAN-20 31-DEC-19
There's an in-built SQL function to do this.
Function Name: TRUNC
SQL> SELECT TRUNC(TO_DATE('17-DEC-2001'),'YEAR') "First Day" FROM Dual;
First Day
---------
01-JAN-01
SQL> SELECT TRUNC(SysDate,'YEAR') "First Day" FROM Dual;
First Day
---------
01-JAN-02
https://www.viralpatel.net/useful-oracle-queries/
No comments:
Post a Comment