Skip to content
Advertisement

Replacing a subquery in a PL/SQL trigger

I have 2 tables. One called Employee and the other Employee_jobs. One of the fields in the Employee table is job_name. The Employee_jobs table contains 2 fields, job_name, and Emp_count (number of employees per job). What i’m trying to do is whenever i perform an operation on the Employee table then it would automatically adjust the Employee_jobs table. This basically means i have to add all the job names from the first table and count the amount of people per job into the second table. This is what i’ve come up with.

I still have to do the update part but i want to get this to work first. I realized using a subquery within the logic block is not allowed but i am not sure how to replace that statement. I figured that i would need to check if the job is already present or not in the second table and take different actions based on that.

I am required to use a Trigger to make this possible.

Advertisement

Answer

You can simplify the trigger. First check if the value exists in the table. Then do a single update:

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