How to select dates between two dates in an Oracle query?

How to select dates between two given dates in an Oracle query?

+3
source share
7 answers
SELECT * FROM your_table WHERE your_date_field BETWEEN DATE '2010-01-01' AND DATE '2011-01-01';
+8
source
SELECT TO_DATE('12/01/2003', 'MM/DD/YYYY') - 1 + rownum AS d
FROM all_objects
WHERE TO_DATE('12/01/2003', 'MM/DD/YYYY') - 1 + rownum <= TO_DATE('12/05/2003', 'MM/DD/YYYY')

from

http://forums.devshed.com/oracle-development-96/select-all-dates-between-two-dates-92997.html

+7
source

LEVEL , , , ​​ 20 , :

select trunc(sysdate+lvl) from
  (select level lvl from dual connect by level < ((sysdate+20)-sysdate - 1) )
order by 1  

, , .

select trunc(early_date+lvl) from
  (select level lvl from dual connect by level < (later_Date-early_date-1) )
order by 1 

, .

+3

"". :

select * from someTable where dateCol between date1 and date2;

, dateCol 1, 2 . , to_date.

+1

, PL SQL .

PL SQL TO_DATE (, ), .

SELECT * FROM order_details
WHERE order_date 
BETWEEN 
TO_DATE ('2014/02/01', 'yyyy/mm/dd') 
AND 
TO_DATE ('2014/02/28', 'yyyy/mm/dd');

SELECT * FROM order_details 
WHERE order_date >= TO_DATE('2014/02/01', 'yyyy/mm/dd') 
AND order_date <= TO_DATE('2014/02/28','yyyy/mm/dd');
0
select * from yourtable where somedate between sysdate and sysdate - 42
-1

with all_days as (select trunc (to_date ('12 -03-2017 ',' dd-mm-yyyy ') + levl) -1 as all_dates out (select the levl level from the double connection by level <(sysdate-to_date ('12 -03-2017 ',' DD-MM-YYYY ') + 1)) order 1) select count (*) as no_of_days from all_days, where ltrim (rtrim (to_char (all_dates,' DAY '))) is not in (' SATURDAY ',' SUNDAY ');

-1
source

Source: https://habr.com/ru/post/1793029/


All Articles