How do I merge two similar database-schema in PL/SQL?

前端 未结 3 1083
小鲜肉
小鲜肉 2021-01-15 02:44

The database-schema (Source and target) are very large (each has over 350 tables). I have got the task to somehow merge these two tables into one. The data itself (whats in

3条回答
  •  灰色年华
    2021-01-15 03:09

    1st of all, for 350 tables, most probably, would need an dynamic SQL.

    1. Declare a CURSOR or a COLLECTION - table of VARCHAR2 with all table names.
    2. Declare a string variable to build the dynamic SQL.
    3. loop through the entire list of the tables name and, for each table generates a string which will be executed as SQL with EXECUTE IMMEDIATE command.
    4. The dynamic SQL which will be built, should insert the values from source table into the target table. In case the PK already exists, in target table, should be checked the field which represents the last updated date and if in source table it is bigger than in target table, then perform an update in target table, else, do nothing.

提交回复
热议问题