Skip to content
Advertisement

How do i resolve this trigger in pl/sql?

I want to have a trigger that no more than 3 employees work on a given project this is the code that i have but doesn’t work very well, sometimes work and sometimes doesn’t work.

This is all i have in my SQL tables:

Advertisement

Answer

You are not going to do what you want at least with the current row level trigger approach. The reason being that a row level trigger can not access the table that caused it to fire. As a result the statement “select … from empleats … will throw the exception “ORA-04091: table is mutating, trigger/function may not see it” because the trigger fires in response to DML against table empleats. A better process is to make this check in a Business Rules layer, or even the application level. However, if you insist on a trigger, it can be accomplished via an after statement trigger. That trigger does have to (or at least should) deal with possibility multiple projects exceeding the max employee limit. So (See fiddle):

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