Oracle, split a time duration row by one hour period

前端 未结 2 887
面向向阳花
面向向阳花 2020-12-11 10:19

I\'m working on oracle db and I\'m not quite good at Oracle. I\'m trying to split a row by one hour period.

For example, if a time row has given as below,

St

2条回答
  •  暖寄归人
    2020-12-11 11:13

    I have bulit a basic query, you can work around it and get what you want.

    select greatest(Start_time, trunc(Start_time+(level-1)/24, 'hh24')), 
    least(End_time, trunc(Start_time+(level)/24, 'hh24'))
    from log_table 
    connect by level <= floor((dt1-dt2)*24)+1;
    

    Example at sqlfiddle:

    http://sqlfiddle.com/#!4/82625/29

提交回复
热议问题