Insert one record at a time into several tables from a table

I have one apartment MAIN_TABLE. I need to insert records from this table into several TABLES.

eg.

MAIN_TABLE
col1, col2, col3, col4, col5

PARENT1_TABLE
PT1_ID(PK), col1,col2

PARENT2_TABLE
PT2_ID(PK), col3,col4

PARENT2_CHILD_TABLE
P2C_ID(PK), PT2_ID(FK), col5, col6

etc.

The goal is that I have to transfer the record from this MAIN_TABLE apartment to the relational structure defined above.

Any help would be greatly appreciated?

thank

+3
source share
2 answers

In Oracle, you can do Inserts for multiple tables . Create a dummy error registration table

create global temporary table err_dump
  (ORA_ERR_NUMBER$   NUMBER,
  ORA_ERR_MESG$     VARCHAR2(2000),
  ORA_ERR_ROWID$    UROWID(4000),
  ORA_ERR_OPTYP$    VARCHAR2(2),
  ORA_ERR_TAG$      VARCHAR2(2000));

(col1, col2) parent1 (col3, col4) parent2. . LOG ERRORS INTO , , , .

INSERT ALL
      INTO parent1_table (pt1_id, col1,col2)
      VALUES (rn, col1,col2)
      LOG ERRORS INTO err_dump REJECT LIMIT 99999999
      INTO parent2_table (pt2_id, col3, col4)
      VALUES (rn, col3, col4)
      LOG ERRORS INTO err_dump REJECT LIMIT 99999999
   SELECT rownum rn, col1, col2, col3, col4
   FROM MAIN_TABLE;

, MAIN, parent1_table parent2_table, PK, PARENT2_CHILD_TABLE

+7

SQL Server, MAIN_TABLE, INSTEAD OF INSERT . , INSERT MAIN_TABLE , . .

+2

Source: https://habr.com/ru/post/1734494/


All Articles