Home » SQL & PL/SQL » SQL & PL/SQL » Select with Time Range (Oracle Database 11g Enterprise Edition Release 11.2.0.4.0)
Select with Time Range [message #643837] Mon, 19 October 2015 16:29 Go to next message
Duane
Messages: 591
Registered: December 2002
Senior Member
I'm trying to figure out how to select rows based on a 5 minute window. Not sure if I should be using an EXTRACT statement or not.



CREATE TABLE BLACKBOARD_FINAL_GRADE
(
  SEQUENCE   NUMBER ,
  CLASS_NBR  INTEGER,
  TERM       VARCHAR2(6 BYTE),
  EFFDT      DATE DEFAULT sysdate
)

Insert into BLACKBOARD_FINAL_GRADE
   (SEQUENCE, CLASS_NBR, TERM, EFFDT)
 Values
   (1, 40001, 'FS2015', TO_DATE('10/19/2015 14:56:27', 'MM/DD/YYYY HH24:MI:SS'));
Insert into BLACKBOARD_FINAL_GRADE
   (SEQUENCE, CLASS_NBR, TERM, EFFDT)
 Values
   (2, 40002, 'FS2015', TO_DATE('10/19/2015 16:23:39', 'MM/DD/YYYY HH24:MI:SS'));
Insert into BLACKBOARD_FINAL_GRADE
   (SEQUENCE, CLASS_NBR, TERM, EFFDT)
 Values
   (3, 30001, 'FS2015', TO_DATE('10/18/2015 16:24:05', 'MM/DD/YYYY HH24:MI:SS'));
COMMIT;



OUTPUT:

Only records for the current day within a 5 minute window of running the SELECT STATEMENT.


EXAMPLE:

select * 
  from BLACKBOARD_FINAL_GRADE 
    where trunc(sysdate) = trunc(effdt) and
          effdt time is within 5 minutes of sysdate time 



Any examples?

[Updated on: Mon, 19 October 2015 16:30]

Report message to a moderator

Re: Select with Time Range [message #643842 is a reply to message #643837] Tue, 20 October 2015 00:18 Go to previous messageGo to next message
Michel Cadot
Messages: 68776
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

What should be the result for the data you gave?

Re: Select with Time Range [message #643843 is a reply to message #643842] Tue, 20 October 2015 00:23 Go to previous messageGo to next message
Littlefoot
Messages: 21826
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Wouldn't that be
and effdt between sysdate - 5 / (24 * 60) 
              and sysdate + 5 / (24 * 60)

i.e.
between 5 minutes ago
    and 5 minutes later
Re: Select with Time Range [message #643845 is a reply to message #643843] Tue, 20 October 2015 02:49 Go to previous messageGo to next message
cookiemonster
Messages: 13975
Registered: September 2008
Location: Rainy Manchester
Senior Member
and you can lose this:
trunc(sysdate) = trunc(effdt)
Re: Select with Time Range [message #643882 is a reply to message #643843] Tue, 20 October 2015 09:42 Go to previous message
Duane
Messages: 591
Registered: December 2002
Senior Member
That's what I needed. Thanks.
Previous Topic: Insert into table from another table based on joining column
Next Topic: Parallel Procedure Run
Goto Forum:
  


Current Time: Fri Jun 26 07:33:20 CDT 2026