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.
Select *
from Table1
where Table1.Date
between trunc(
trunc(sysdate,'MM') -- first day, this month
-1 -- sub 1 day to last day of previous month
,'MM') -- truncates to first day, last month
and
trunc(sysdate,'MM') -- first day, this month
-(1/24/60/60) -- subtracts 1 second, to last
-- second of last day of previous month
;
Select *
from Table1
where in_prev_month(Table1.Date,sysdate) = 'Y'
;
create or replace function in_prev_month
(date_in date,month_in date)
return varchar2
is
begin
if date_in
between trunc(trunc(month_in,'MM')-1,'MM') and
trunc(month_in,'MM')-(1/24/60/60) then
return 'Y';
else
return 'N';
end if;
end;
/
Function created.
col a heading "Dates"
select to_char(dt,'dd-MON-yyyy "@" hh24:mi:ss') a
from table1
order by dt;
Dates
----------------------
28-AUG-2005 @ 14:38:45
01-SEP-2005 @ 00:00:00
17-SEP-2005 @ 14:38:44
27-SEP-2005 @ 14:38:44
30-SEP-2005 @ 23:59:59
27-OCT-2005 @ 14:38:44
6 rows selected.
Select to_char(dt,'dd-MON-yyyy "@" hh24:mi:ss') a
from Table1
where in_prev_month(Table1.Dt,sysdate) = 'Y'
order by dt;
Dates
----------------------
01-SEP-2005 @ 00:00:00
17-SEP-2005 @ 14:38:44
27-SEP-2005 @ 14:38:44
30-SEP-2005 @ 23:59:59
4 rows selected.
Select to_char(dt,'dd-MON-yyyy "@" hh24:mi:ss') a
from Table1
where in_prev_month(Table1.Dt,sysdate-30) = 'Y'
order by dt;
Dates
----------------------
28-AUG-2005 @ 14:38:45
1 row selected.