标签:col detail vpd ring term oracle break any soft
Oracle with 语句可以实现如同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 c(n) as (select 1 from dual union all select n+1 from c where n<10) select n from c;
更多connect by 用法参考:https://blog.csdn.net/wang_yunj/article/details/51040029/
查询当前时间往前的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', '[^|]+');
标签:col detail vpd ring term oracle break any soft
原文地址:http://blog.51cto.com/aaron521/2132730