Creating multiple dynamic rows in an oracle table

0

I need to create a new table with multiple lines using data from a previous table as a parameter.

For example

_______________________
| nome   | quantidade |
|--------|------------|
| xyz    | 2          |
| abc    | 1          |
-----------------------

Expected

__________________
| nome   | número|
|--------|-------|
| xyz    | 1     |
| xyz    | 2     |
| abc    | 1     |
------------------

In the example I use the quantity data as a parameter for creating N rows according to the quantity, and is populated in the other table with N rows of quantity and filling the column number from 1 to N.

    
asked by anonymous 11.08.2016 / 16:41

1 answer

0
BEGIN
  FOR R IN (SELECT NOME,QUANTIDADE FROM EXEMPLO)
  LOOP
    FOR I IN 1..R.QUANTIDADE
    LOOP
      INERT INTO TABELA (NOME,NUMERO) VALUES (R.NOME,I);
    END LOOP;
  END LOOP;
END; 
    
11.08.2016 / 19:25