ITPub博客

首页 > Linux操作系统 > Linux操作系统 > connect by的应用

connect by的应用

原创 Linux操作系统 作者:tsai_vogue 时间:2013-01-16 10:09:18 0 删除 编辑
需求:
   item       cnt
      A          4
      B          3
      C          3

得到结果:
    item
    A1
    A2
    A3
   A4
   B1
  B2 
  B3
  C1
  C2
  C3


语句:
 with t as(
 select 'A' item,4 cnt from dual
 union all
 select 'B',3 from dual
 union all
 select 'C',3 from dual
 )
 select t.item || rn item
   from t,
        (select rownum rn
           from dual
         connect by rownum <= (select max(cnt) from t)) t1
  where t.cnt >= t1.rn
  order by item, rn
ITEM
-----------------------------------------
A1
A2
A3
A4
B1
B2
B3
C1
C2
C3
 
10 rows selected

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26918004/viewspace-752730/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 不规则的行转列
下一篇: 游标
请登录后发表评论 登录
全部评论

注册时间:2012-12-19

  • 博文量
    10
  • 访问量
    13110