Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
CREATE OR REPLACE FUNCTION LastFullMonth (DT_IN DATE) return varchar2 IS
BEGIN
if dt_in is null then
return 'NULL';
end if;
IF DT_IN BETWEEN TRUNC(ADD_MONTHS(SYSDATE,-1),'mm') -- Midnight on Day of last month
AND TRUNC(SYSDATE,'MM')-(1/24/60/60) -- 11:59:59 of last month
THEN
RETURN 'TRUE';
ELSE
RETURN 'FALSE';
END IF;
END;
/
select * from <table_name>
where LastFullMonth (<date_column>) = 'TRUE';
select last_name,start_date
from s_emp
order by start_date;
LAST_NAME START_DATE
------------------- ----------
Giljum 19-DEC-11
Urguhart 19-DEC-11
Nguyen 23-DEC-11
Maduro 08-JAN-12
Nozaki 10-JAN-12
Catchpole 10-JAN-12
Sedeghi 19-JAN-12
Velasquez 28-JAN-12
Havel 28-JAN-12
Ropeburn 03-FEB-12
Ngao 07-FEB-12
Smith 07-FEB-12
Dancs 16-FEB-12
Quick-To-See 08-MAR-12
Biri 08-MAR-12
Schwartz 09-APR-12
Magee 14-APR-12
Menchu 14-APR-12
Markarian 26-APR-12
Nagayama 18-MAY-12
Newman 21-JUN-12
Patel 07-JUL-12
Dumas 09-SEP-12
Patel 17-SEP-12
Chang 31-OCT-12
25 rows selected.
select last_name,start_date
from s_emp
where LastFullMonth(start_date) = 'TRUE';
LAST_NAME START_DATE
------------------- ----------
Dumas 09-SEP-12
Patel 17-SEP-12
2 rows selected.
Elapsed: 00:00:00.01
select 'This works fine.'
from dual
where LastFullMonth(sysdate - 20) = 'TRUE';
'THISWORKSFINE.'
--------------------
This works fine.
1 row selected.
Elapsed: 00:00:00.03