Create Explicit Cursor - PL/SQL Program

Consider the following tables to complete the following assignment.

Table 1:  'Emp_Detail'

Employee_idFirst_NameLast_nameSalaryDEPT_ID
1ShrutiShrabya500001
2JayaSingh100002
3MangalaThokal600003
4SurendraMaurya700004

Table2: 'Department'

Dept_IDDept_NameManager_ID
1Accounting1
2Shipping3
3Store3

Q.  Write a PL/SQL block to create a explicit cursor using For Loop and display the employees who have salary greater than 48000.

Answer:

DECLARE
CURSOR c_detail IS
  SELECT dept_name,d.dept_id,first_name,salary
              FROM department d JOIN emp_detail e
              ON e.dept_id = d.dept_id
              WHERE  salary > 48000;               
BEGIN
  FOR item IN c_detail
    LOOP
DBMS_OUTPUT.PUT_LINE(item.first_name||' '||item.dept_name||' '||item.dept_id||' '||' '||item.salary);
    END LOOP;
END;


This code will create a explicit cursor and display the records of employees for selected columns and employees who have salary greater the 48000.

Output:

explicit cursor using for loop