Oracle - Overlaps function


/ Published in: SQL
Save to your folder(s)

This function can be used to find out if there exists an overlap between two pairs of dates or time.

There is an alternate way to calculate the actual overlapping value - Read the snippet "How to avoid double counts"


Copy this code and paste it in your HTML
  1. -- Overlap present
  2.  
  3. SELECT 'YES' AS overlap FROM dual
  4. WHERE (DATE '2007-01-01', DATE '2008-01-01')
  5. overlaps (DATE '2005-01-01', DATE '2009-01-01')
  6.  
  7.  
  8. OVE
  9. ---
  10. YES
  11.  
  12. -- Overlap not present
  13.  
  14. SELECT 'YES' AS overlap FROM dual
  15. WHERE (DATE '2007-01-01', DATE '2008-01-01')
  16. overlaps (DATE '2005-01-01', DATE '2006-01-01')
  17.  
  18.  
  19. no ROWS selected.

URL: http://oraclesponge.wordpress.com/2008/06/12/the-overlaps-predicate/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.