oracle - Repeat each value n times as rows in SQL -


i have been trying achieve in sql (oracle 11g) while , not find proper way it.

my table names has following rows:

name      repeat ----      ------ kaushik   2 karthik   3 nidhi     1 ashwini   5 jagadeesh 6 

what need output this:

name ---- kaushik    -- 2 rows kaushik karthik karthik    -- 3 rows karthik nidhi      -- 1 row ashwini ashwini    -- 5 rows ... 

and on.

one of queries have tried far off course not working. tried use unpivot not seem find proper way accomplish this.

select m.name names m inner join   ( select name, repeat names   ) n on m.name = n.name   connect level <= n.repeat; 

try this:

select * names cross join (select rownum n dual             connect level <= (select max(repeat) names)) n <= repeat order name 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

Qt QGraphicsScene is not accessable from QGraphicsView (on Qt 5.6.1) -

What is happening when Matlab is starting a "parallel pool"? -