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

  • pl/sql

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

الأجوبة

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.
هل كان المحتوى مفيد؟

معلومات ذات صلة

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...