Q:

Write a program in PL/SQL to FETCH multiple records and more than one columns from the same table

0

Write a program in PL/SQL to FETCH multiple records and more than one columns from the same table.

All Answers

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

DECLARE
    v_emp_rec employees%ROWTYPE;
    CURSOR cur_emp_name IS
      SELECT *
      FROM   employees;
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
                             || '  ::   Salary: '
                             || v_emp_rec.salary);
    END LOOP;
    CLOSE cur_emp_name;
END; 
/

Sample Output:

SQL> /
Name: Steven  ::   Salary: 24000
Name: Neena  ::   Salary: 17000
Name: Lex  ::   Salary: 17000
Name: Alexander  ::   Salary: 90
Name: Bruce  ::   Salary: 6000
Name: David  ::   Salary: 4800
Name: Valli  ::   Salary: 4800
Name: Diana  ::   Salary: 4200
Name: Nancy  ::   Salary: 12008
Name: Daniel  ::   Salary: 9000
...

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