Oracle with 语句可以实现如同connect by 语句一样的序列:
connect by用法
使用rownum实现1到10的序列。select rownum from dual connect by rownum<=10;
使用level实现1到10的序列。select level from dual connect by level<=10;
with 可实现同样功能用法:with c(n) as
(select 1 from dual
union all
select n+1 from c
where n<10)
select n from c;
查询当前时间往前的12周的开始时间、结束时间、第多少周:
select sysdate - (to_number(to_char(sysdate - 1, 'd')) - 1) -
(rownum - 1) * 7 as startDate,
sysdate + (7 - to_number(to_char(sysdate - 1, 'd'))) -
(rownum - 1) * 7 as endDate,
to_number(to_char(sysdate, 'iw')) - rownum + 1 as weekIndex from dualconnect by level<= 12;--将level改成rownum可以实现同样的效果
d 表示一星期中的第几天
iw 表示一年中的第几周
字符串分割,由一行变为多行:
比如说分割01|02|03|04这种有规律的字符串select REGEXP_SUBSTR('01|02|03|04', '[^|]+', 1, rownum) as newport
from dual
connect by rownum <= REGEXP_COUNT('01|02|03|04', '[^|]+');