Employee Empno Ename Job NGRI Hiredate | Sal |Comm) DeptNo 7839King President 76
ID: 3912531 • Letter: E
Question
Employee Empno Ename Job NGRI Hiredate | Sal |Comm) DeptNo 7839King President 7698 Blake 7782 IClark 7566 Johns M 02-Apr-81 7654 Martin Salesman 7698 28-S 7499 Allen Salesman 7698 20-Feb-81 16 7844 Turner Salesman 7698 108-S 7900 James Clerk 7521 7902 Ford 7369 Smith Clerk 7788 Sct Anal 7876 Adams Clerk 7934 Miller Clerk 17-Nov-81 10 30 Manager 7839 01-May-81 2850 Manager 783909-Jun-812450 Manager 7839 20 30 8112 7698 03-Dec-81 950 rd Salesmanl 7698 22-Feb-81125 7566 03-Dec-81 7902 17-Dec-80 800 7566 09-Dec-8230 7788 12-Jan-83 1100 7782 23-Jan-8213 20 20 20 Department DeptNo Dname Location 10 20 30 Accountin Research Sharaiah Sales man Abu Dhabi Dubai . Create a PL/SQL block to declare a cursor EMP CUR to select the employee name, salary, and hire date from the EMPLOYEES table. Process each row from the cursor, and if the salary is greater than 2,000 and the hire date is greater than 01-FEB-1981, display the employee name, salary, and hire date in the screenExplanation / Answer
DECLARE
TYPE emp_rec IS RECORD( --to create the new record
emp_name Employee.Ename%TYPE, --create emp_name variable with data type same as Ename
salary Employee.Sal%TYPE, --create salary variable with data type same as Sal
hire Employee.Hiredate%TYPE --create hire variable with data type same as Hiredate
);
CURSOR EMP_CUR IS --declaring/creatimg the cursor
--the statements that cursor is going to execute
SELECT Ename,Sal,Hiredate
FROM Employee
--condition to fetch the rows where salary >2000 and the hire date is > 01-FEB-1981
WHERE Sal>2000 AND Hiredate>to_date('01-FEB-1981',DD-MON-YYYY);
BEGIN
OPEN EMP_CUR; --open the cursor to execute
FETCH EMP_CUR INTO emp_rec; --storing the rows that are triggered by cursor into record
dbms_output.put_line(emp_rec.emp_name || ',' || emp_rec.salary || ',' || emp_rec.hire); --displaying the output
CLOSE EMP_CUR; --closing the cursor
END;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.