Domanda

My query is , I need to give input a month ,i.e ex :input will be 'MAR' then i need to get 1st date and last date for the March month .

select to_char(trunc(trunc(sysdate, 'MM'), 'MM'),'DD-MON-YYYY') "First Day of Last Month"
       , to_char(trunc(sysdate, 'MM') ,'DD-MON-YYYY') "Last Day of Last Month"
 from dual ;

Any one please help..

È stato utile?

Soluzione

month_start := to_date('MAR', 'MON');
month_end := last_day(month_start);
  • Month names depend on specifics of the NLS language/territory so may need to tweak them. (alter session set nls_language/nls_territory = AMERICAN/AMERICA).
  • You haven't mentioned what would be the year, so the assumption is that you need current one.

If the year is also a variable input:

month_start := to_date('2015-MAR', 'yyyy-MON');
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top