oraclewith语句实现递归查询

Oracle with 语句可以实现如同connect by 语句一样的序列:

主要从事网页设计、PC网站建设(电脑版网站建设)、wap网站建设(手机版网站建设)、响应式网站开发、程序开发、微网站、微信小程序开发等,凭借多年来在互联网的打拼,我们在互联网网站建设行业积累了丰富的成都做网站、成都网站设计、成都外贸网站建设、网络营销经验,集策划、开发、设计、营销、管理等多方位专业化运作于一体,具备承接不同规模与类型的建设项目的能力。

connect by用法

使用rownum实现1到10的序列。

select rownum from dual connect by rownum<=10;

oracle with 语句实现递归查询

使用level实现1到10的序列。

select level from dual connect by level<=10;

oracle with 语句实现递归查询

with 可实现同样功能用法:

with c(n) as
(select 1 from dual
union all
select n+1 from c
where n<10)
select n from c;

oracle with 语句实现递归查询

更多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可以实现同样的效果

oracle with 语句实现递归查询

  • d 表示一星期中的第几天

  • iw 表示一年中的第几周

字符串分割,由一行变为多行:

  1. 比如说分割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', '[^|]+');

分享文章:oraclewith语句实现递归查询
URL分享:http://lszwz.com/article/piopgd.html

其他资讯

售后响应及时

7×24小时客服热线

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款