Skip to content
Advertisement

How to successfully reference another table before insert with a trigger

I’m trying to create a trigger to validate if a new entry in the table registraties (registrations) contains a valid MNR (employee number) but I’m getting stuck on the part where I’m referencing the table medewerkers (employees).

Could someone help me out?

Error message received is
ORA-24344: success with compilation error

Advertisement

Answer

The PL/SQL assignment operator is :=, or select x into y from z to populate from a SQL query.

FOR EACH ROW is part of the trigger spec, not the PL/SQL code.

If :new.mnr is not present in the parent table, you will get a no_data_found exception, not a mismatched variable.

It’s good practice for error messages to include details of what failed.

In programming, we use indentation to indicate code structure.

A fixed version would be something like:

However, we can implement this kind of check better using a foreign key constraint, for example:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement