Creation of multiple dynamic lines in an oracle table

Asked

Viewed 50 times

0

I need to create a new table with multiple rows using data from a previous table as 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 to create N rows according to the quantity, and it is populated in the other table with N quantity lines and filling the column number from 1 to N.

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; 
  • It worked perfectly, I created a stored Procedure.. thank you very much for your help !!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.