Trigger to Retrieve Last Record Inserted in PL-SQL Table

Asked

Viewed 358 times

0

I have a Rigger that after being inserted a new user in the table tFunctioning I must fill another table tPlanoSaude with the data of the employee.

employee table

inserir a descrição da imagem aqui

table Health Plan

inserir a descrição da imagem aqui

Code of the Trigges

 CREATE OR REPLACE TRIGGER INSERTFUNCIONARIO 
    BEFORE INSERT ON tfuncionario 
    BEGIN
      INSERT INTO tPlanoSaude VALUES(
          :old.TFUNCIONARIO.MATRICULA,
          :old.TFUNCIONARIO.NOME);
    END;

Error message:

inserir a descrição da imagem aqui

  • Include the FOR EACH ROW in the line below the BEFORE.

  • Perfect. working!

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

  • added the reserved words :new. before the columns for which I want to recover the value

2 answers

2


The variable :NEW and :OLD is already the table itself with the inserted and Deleted data respectively, it is not neecssário to pass the table: :NEW.TABELA.CAMPO

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

1

I managed to run Rigger 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;

Browser other questions tagged

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