展开全部
可以的,用connected by level结构实现。
比如:
表结构数据现在e68a84e8a2ad62616964757a686964616f31333339663332是这样:
code stime etime
0001 08:00 12:00
0002 14:30 17:30
使用connect by level来得到每30分钟一条记录的结果,如下:WITH
t
AS
(
SELECT '0001' AS code, '08:00' AS stime, '12:00' AS etime
FROM dual
UNION
SELECT '0002' AS code, '14:30' AS stime, '17:30' AS etime
FROM dual
)
SELECT code, decode(level, 1, stime, to_char(to_date(stime, 'hh24:mi') + 30.0 / 60 / 24 * (level - 1), 'hh24:mi')), decode(level, (to_date(etime, 'hh24:mi') - to_date(stime, 'hh24:mi')) * 24 * 60 / 30, etime, to_char(to_date(stime, 'hh24:mi') + 30.0 / 60 / 24 * level, 'hh24:mi')), level
FROM t
CONNECT BY code = PRIOR(code
AND PRIOR(dbms_random.value IS NOT NULL
AND level <= (to_date(etime, 'hh24:mi') - to_date(stime, 'hh24:mi')) * 24 * 60 / 30))
运行结果
code stime etime
0001 08:00 08:30
0001 08:30 09:00
0001 09:00 09:30
0001 09:30 10:00
0001 10:00 10:30
0001 10:30 11:00
0001 11:00 11:30
0001 11:30 12:00
0002 14:30 15:00
0002 15:00 15:30
0002 15:30 16:00
0002 16:00 16:30
0002 16:30 17:00
0002 17:00 17:30