Oracle 再谈 connect by level

 在开发的过程中遇到需要把一行数据显示成N行,当时马上就想到了connect by level  这个实在太好用了

显示一行

 select level rn from dual connect by level < 2;

显示二行

 select level rn from dual connect by level < 3;

 

实例:目前显示一行

 select pha.segment1, pha.type_lookup_code, pha.authorization_status
     from po_headers_all pha
    where pha.po_header_id = 3085

结果:显示一行

 

修改后显示两行:

select pha.segment1, pha.type_lookup_code, pha.authorization_status
     from po_headers_all pha,
          (select level rn from dual connect by level < 3)
    where pha.po_header_id = 3085

结果:显示两行

 

执行计划也是相当优秀的:

 

posted @ 2024-04-08 15:26  Iven_lin  阅读(250)  评论(0)    收藏  举报