Q:

Write a program in PL/SQL to print a list of managers and the name of the departments

0

Write a program in PL/SQL to print a list of managers and the name of the departments.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

DECLARE
  CURSOR cur_mgr IS
      SELECT first_name,
             last_name,
             department_name
      FROM employees e
      INNER JOIN departments d ON d.manager_id = e.employee_id;
 
  v_mgr cur_mgr%ROWTYPE;
BEGIN
  OPEN cur_mgr;
  LOOP
    -- fetch information from cursor into record
    FETCH cur_mgr INTO v_mgr;
    EXIT WHEN cur_mgr%NOTFOUND;
    DBMS_OUTPUT.PUT_LINE(v_mgr.department_name || ' :: ' ||
                         v_mgr.first_name || ' ' ||
                         v_mgr.last_name);
  END LOOP;
  CLOSE cur_mgr;
END;
/

Sample Output:

SQL> /
Executive :: Steven King
IT :: Alexander Hunold
Finance :: Nancy Greenberg
Purchasing :: Den Raphaely
Shipping :: Adam Fripp
Sales :: John Russell
Administration :: Jennifer Whalen
Marketing :: Michael Hartstein
Human Resources :: Susan Mavris
Public Relations :: Hermann Baer
Accounting :: Shelley Higgins

PL/SQL procedure successfully completed.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now