Trigger to retrieve Last Record Inserted into table in PL-SQL

0

I have a trigger that after inserting a new user in the table tFuncionario I have to fill another table tPlanoSaude with the data of the official.

Employee table

HealthPlantable

TriggersCode

CREATEORREPLACETRIGGERINSERTFUNCIONARIOBEFOREINSERTONtfuncionarioBEGININSERTINTOtPlanoSaudeVALUES(:old.TFUNCIONARIO.MATRICULA,:old.TFUNCIONARIO.NOME);END;

Errormessage:

    
asked by anonymous 08.02.2018 / 21:02

2 answers

2

The variable :NEW and :OLD is already the table itself with the data of inserted and deleted respectively, it is not necessary to pass the table: :NEW.TABELA.CAMPO

Only :NEW.CAMPO , where :NEW already refers to your table.

    
08.02.2018 / 22:06
1

I was able to execute the trigger with this code snippet:

CREATE OR REPLACE TRIGGER INSERTFUNCIONARIO 
BEFORE INSERT ON tfuncionario 
FOR EACH ROW
BEGIN
  INSERT INTO tPlanoSaude VALUES(:new.matricula,:new.MATRICULA);
END;
    
08.02.2018 / 21:47