How to get the timestamp per minute for the given interval

Hello

I have a table with a date of beginning and end of time columns. I need to divide the date given in one minute interval and post the results.

create table min_data(objectid varchar2(20),starttime timestamp,endtime timestamp,duration number);


SET DEFINE OFF;
Insert into MIN_DATA Values ('U1_B011_P006_InvA', TO_DATE('06/23/2015 02:42:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('06/23/2015 02:46:00', 'MM/DD/YYYY HH24:MI:SS'), 5);
Insert into MIN_DATA Values ('U1_B011_P006_InvA', TO_DATE('06/23/2015 12:43:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('06/23/2015 12:44:00', 'MM/DD/YYYY HH24:MI:SS'), 2);
COMMIT;




My expected output should be something like this. INT_TIMESTAMP is the timestamp calculated for the given interval (time of start and end times)

INT_TIMESTAMPOBJECTIDSTARTTIMEEND TIME
23/06/2015-02:42U1_B011_P006_InvA23/06/2015-02:4223/06/2015-02:46
23/06/2015-02:43U1_B011_P006_InvA23/06/2015-02:4223/06/2015-02:46
23/06/2015-02:44U1_B011_P006_InvA23/06/2015-02:4223/06/2015-02:46
23/06/2015-02:45U1_B011_P006_InvA23/06/2015-02:4223/06/2015-02:46
23/06/2015-02:46U1_B011_P006_InvA23/06/2015-02:4223/06/2015-02:46
23/06/2015 12:43U1_B011_P006_InvA23/06/2015 12:4323/06/2015 12:44
23/06/2015 12:44U1_B011_P006_InvA23/06/2015 12:4323/06/2015 12:44

I wrote a query that works for one set of intervals.

With get_data AS(
SELECT   a.*,
         starttime -1/1440 v_s_date,
         endtime v_e_date
FROM min_data a
where duration=5)
SELECT v_s_date + ((1 / 1440) * DECODE(LEVEL, 1, 1, LEVEL)) int_timestamp, objectid,starttime,endtime
          FROM get_data d
         WHERE MOD(LEVEL, 1) = 0
            OR LEVEL = 1
        CONNECT BY LEVEL <= (v_e_date - v_s_date) * 1440;

Please send me a SQL query that gives me the timestamps of minutes between intervals.

Hello

The following query works for any number of intervals

SELECT STARTTIME + ((LVL-1) / 1440) INT_TIMESTAMP, OBJECTID, STARTTIME, ENDTIME

Of

(SELECT LEVEL LVL FROM DUAL CONNECT BY LEVEL< 10)="">

(SELECT * FROM MIN_DATA)

WHERE STARTTIME + ((LVL-1) / 1440) BETWEEN STARTTIME AND ENDTIME ORDER BY, STARTTIME, ENDTIME LVL;

Concerning

Salim

Tags: Database

Similar Questions

Maybe you are looking for