Procedure oracle to copy data between tables

Asked

Viewed 1,914 times

4

I need to make a trial copy of my TAB_FORNECEDOR table, everything you have in it and pass to TAB_FORNECEDOR2 table.

I know I need to make a loop cursor, a commit delete before everything, can give me a light on how to assemble my project?

  • 2

    Hello Welcome to [en.so]. I adjusted your title to be more consistent with the question raised. If you want to reverse my edition.

  • 3

    Have you done anything? Post an excerpt from your code

1 answer

5

One solution is to create the table from scratch with the data from the previous one:

CREATE TABLE
   TAB_FORNECEDOR2
AS
   SELECT
      *
   FROM
      TAB_FORNECEDOR;

Recalling that to do so you must remove TAB_FORNECEDOR2 if it already exists.

If you just need to keep both synchronized, you’d better give more details on the question.

Important: if you need to define constraints in the copy, you will have to do this manually, because the CREATE AS does not copy indexes, triggers, etc.

If you want to copy only the data, you can use this syntax:

INSERT INTO
   TAB_FORNECEDOR2 (
      campo1,
      campo2
      ...
   )
SELECT
   TAB_FORNECEDOR.campo1 ...
FROM
   TAB_FORNECEDOR

And optionally you can use a WHERE to filter the desired lines.

  • I have to make a proc that takes the fields of table "SUPPLIER" and copy to table "FORNECEDORES2", but I have to create a proc that copies only fields from one table to another.

Browser other questions tagged

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