Q:

Write a program in PL/SQL to FETCH multiple records and more than one columns from different tables

0

Write a program in PL/SQL to FETCH multiple records and more than one columns from different tables.

Below example we are trying to fetch department names and employee names.

All Answers

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

DECLARE
    CURSOR cur_emp_name IS
      SELECT first_name,
             last_name,
             department_name
      FROM   employees e,
             departments d
      WHERE  d.department_id = e.department_id;
    v_emp_rec cur_emp_name%ROWTYPE;
BEGIN
    OPEN cur_emp_name;
    LOOP
        FETCH cur_emp_name INTO v_emp_rec;
        exit WHEN cur_emp_name%NOTFOUND;
        dbms_output.Put_line('Name:  '
                             || v_emp_rec.first_name
                             || '  '
                             ||v_emp_rec.last_name
                             || '   ::   department: '
                             || v_emp_rec.department_name);
    END LOOP;
    CLOSE cur_emp_name;
END; 
 /

Sample Output:

SQL> /
Name:  Jennifer  Whalen   ::   department: Administration
Name:  Pat  Fay   ::   department: Marketing
Name:  Michael  Hartstein   ::   department: Marketing
Name:  Sigal  Tobias   ::   department: Purchasing
Name:  Karen  Colmenares   ::   department: Purchasing
Name:  Shelli  Baida   ::   department: Purchasing
Name:  Den  Raphaely   ::   department: Purchasing
Name:  Alexander  Khoo   ::   department: Purchasing
Name:  Guy  Himuro   ::   department: Purchasing
Name:  Susan  Mavris   ::   department: Human Resources
Name:  Kevin  Feeney   ::   department: Shipping
Name:  Jean  Fleaur   ::   department: Shipping
Name:  Adam  Fripp   ::   department: Shipping
...

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