I can not understand how an Oracle size company did not have the ability to think of a function like that. After last_day, I'll introduce you to First_Day.
Select all
create or replace
FUNCTION FIRST_DAY (pDATA IN DATE DEFAULT SYSDATE) RETURN DATE AS
begin
--Retorna o primeiro dia do mês passado no parâmetro
RETURN last_day(add_months(pDATA,-1))+1;
END FIRST_DAY;
to test ....
Select all
SQL> select first_day(sysdate)
2 , last_day(sysdate)
3 from dual
4 /
FIRST_DAY(SYSDATE) LAST_DAY(SYSDATE)
------------------ -----------------
01/03/2011 31/03/2011
found in the environment of production.