In Oracle, I want to get specific intervals.
Consider, sysdate is 10-dec-2016 10:15:23 (dd-mon-yyyy hh24:mi:ss). I want to get a date period like 10-dec-2016 09:00:00 to 10-dec-2016 10:00:00
How to get this date period through query. If you have observed this date period is 1hr back from current HH24 format and rounded to 00:00. The query should work for whatever I set. Above date period is for 1hr. I should be able to set for any number of hours like 2hrs,3hrs etc.
Here is an example
This would be a generic function you can use for any interval which fits into "higher range"
For other intervals use
INTERVAL '2' HOUR
orINTERVAL '30' MINUTE
, etc.Something like:
if you need it in a SQL statement, or:
if you need it in PL/SQL (to save unnecessary context switching between SQL and PL/SQL).