Assuming you have to copy a model identified by MODEL_ID=old_model_id
first of all you have to create a new MODEL_ID (for example stored in a variable called new_model_id
), for example using a sequence (called SEQ_ID_MODEL
in below code, but you could use another technique to create a new ID).
Then you have to write an insert command for each of the 4 tables retrieving the model to copy with the old id (old_model_id
) and inserting using the new one(new_model_id
):
PROCEDURE P_COPY_MODEL
(
old_model_id IN NUMBER
)IS
new_model_id number;
begin
select SEQ_ID_MODEL.nextval into new_model_id from dual;
insert into table1(MODEL_ID, COLUMN_1, COLUMN_2, ..., COLUMN_N)
select (new_model_id, COLUMN_1, COLUMN_2, ..., COLUMN_N)
from table1 where MODEL_ID = old_model_id;
insert into table2(MODEL_ID, COLUMN_1, COLUMN_2, ..., COLUMN_M)
select (new_model_id, COLUMN_1, COLUMN_2, ..., COLUMN_M)
from table2 where MODEL_ID = old_model_id;
--and so on for table3 and table4
end;