3 for each row 4 begin 5 increment the employee count

Info icon This preview shows pages 2–3. Sign up to view the full content.

View Full Document Right Arrow Icon
3: FOR EACH ROW 4: BEGIN 5: --Increment the employee count for the department 6: --referenced by the record just inserted. 7: UPDATE department 8: SET no_of_emps = NVL(no_of_emps,0)+1 9: WHERE dept_id = :NEW.dept_id; 10: END; 11: / 12: On Delete: 13: CREATE OR REPLACE TRIGGER emp_dept_del 14: AFTER DELETE ON emp_dept 15: FOR EACH ROW 16: BEGIN 17: --Decrement the employee count for the department 18: --referenced by the record just deleted. 19: UPDATE department 20: SET no_of_emps = no_of_emps-1 21: WHERE dept_id = :OLD.dept_id; 22: END; On Update: 25: CREATE OR REPLACE TRIGGER emp_dept_upd 26: AFTER UPDATE OF dept_id ON employees 27: FOR EACH ROW 28: BEGIN 29: --Increment the employee count for the employee’s new department 30: UPDATE department 31: SET no_of_emps = NVL(no_of_emps,0)+1 32: WHERE dept_id = :NEW.dept_id; 33: 34: --Decrement the employee count for the employee’s 35: --previous department. 36: UPDATE department 37: SET no_of_emps = no_of_emps - 1 38: WHERE dept_id = :OLD.dept_id; 39: END; drop trigger emp_dept_ins ALTER TRIGGER emp_dept_ins DISABLE; NVL function: in Oracle/PLSQL, the NVL function lets you substitute a value when a null value is encountered.
Image of page 2

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern