Modifying Update Between Two Oracle Tables

1

I need to do an integration between two sws in the house and I need help.

I have an integration table (3rd) that will receive the data of a new management, if it is created or modified.

For this, I have a view that brings the source data and I have a table with all the managements registered in the destination to make a comparison.

The idea is to make a comparison between source and destination. If there is a management name in the source that does not exist in the destination, it compares the ids. If the Id does not exist, it inserts the information in a 3rd table. If Id exists, enter the same data in the 3rd table. The source table may return many rows in this comparison.

My problem is with the comparison. I can not program so that I have only 1 line corresponding to the ID and the new Management, which will be inserted in my 3rd table.

    
asked by anonymous 04.06.2014 / 03:20

2 answers

3
  

The idea is to make a comparison between source and destination. Case   there is a management name in the source that does not exist in the destination,   compare the ids. If the Id does not exist, it inserts the information in a 3rd   table. If Id exists, enter the same data in the 3rd table. THE   source table may return countless rows in this comparison.

CREATE OR REPLACE PROCEDURE SP1 IS
  VN_NOME DESTINO.NOME%TYPE;
BEGIN
  FOR RORIGEM IN (SELECT ID,NOME FROM ORIGEM)
  LOOP
    BEGIN
      SELECT NOME INTO VN_NOME 
      FROM DESTINO WHERE ID = RORIGEM.ID;
      IF VN_NOME <> RORIGEM.NOME THEN
      END IF;
      UPDATE DESTINO SET NOME = RORIGEM.NOME
      WHERE ID = RORIGEM.ID;
    EXCEPTION
      WHEN NO_DATA_FOUND THEN
        INSERT INTO TABELA3 (ID,NOME) VALUES (RORIGEM,.ID,R.ORIGEM.NOME);
      WHEN OTHERS THEN
        RAISE;
    END;
  END LOOP;
END;

I think that would be more or less this.

    
04.06.2014 / 17:19
0
       update RDESTINO a
          set (a.nome) = 
              (select b.nome                 
                  from RORIGEM b
                where a.chave = b.chave)
          where a.documento = variavel and
          Exists (select * from RORIGEM b 
                     where (a.chave = b.chave));

Here is an example of another syntax, which works well and is very fast, you can use multiple tables in Select. I put a variable in the Where to table of RDESTINO and filtering by a key in the RORIGEM table, if you do not need, just take the variable and keep Where Exists (...)

I hope I have helped

    
02.03.2018 / 11:25