2016-09-18 66 views

回答

1

在Oracle 11g中+,你可以使用遞歸查詢:

with cte(name, ind, count) as (
     select t.name, 1 as ind, t.count 
     from t 
     union all 
     select cte.name, cte.ind + 1, cte.count 
     from cte 
     where cte.ind < cte.count 
    ) 
select cte.name || cte.ind 
from cte; 

我更喜歡遞歸CTE到CONNECT BY,因爲前者是標準的並且受大多數數據庫支持。

+0

返回錯誤:ora-32039 – zhanzezhu

+0

@ zhanzezhu。 。 。哎呀,我忽略了列名。 –

+0

謝謝你的回答。 – zhanzezhu

0

你做得很好,但你應該將group by子句添加到上面的select語句中。

select d from 
(select (t.NAME || level)d 
    from Test t 
CONNECT BY LEVEL <= t.CT) 
group by d 
order by d 

效果很好。