Repeat each value n times as rows in SQL

前端 未结 4 1616
盖世英雄少女心
盖世英雄少女心 2021-01-28 05:36

I have been trying to achieve this in SQL (Oracle 11g) for a while but could not find a proper way to do it.

My table names has the following rows:

4条回答
  •  北荒
    北荒 (楼主)
    2021-01-28 06:10

    I just found an alternative with connect by and correlated sub-query.

    select name
    from   names o
    connect by level <= ( select repeat from names 
                            i where i.name = o.name )
    AND                        
    prior name = name and
               prior sys_guid() is not null
               order by name;
    

提交回复
热议问题