0% found this document useful (0 votes)
21 views

'E01' 'Jade' '24-Feb-2019' 'E04'

1. The document creates an Emp_Test table with employee data and inserts sample records. 2. It defines a cursor to select the top 3 highest paid employees and prints their names and salaries. 3. A procedure is created to accept a department number, select employee names, salaries, and managers from that department and output it. The procedure is then called for departments 20 and 30. 4. A procedure is created to accept a table and employee name and increase the salary of that employee by 5000 in the given table. It is then called to increase salaries for employees 'LUCY' and 'JADE' in the Emp_Test table.

Uploaded by

Rakesh Maher
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

'E01' 'Jade' '24-Feb-2019' 'E04'

1. The document creates an Emp_Test table with employee data and inserts sample records. 2. It defines a cursor to select the top 3 highest paid employees and prints their names and salaries. 3. A procedure is created to accept a department number, select employee names, salaries, and managers from that department and output it. The procedure is then called for departments 20 and 30. 4. A procedure is created to accept a table and employee name and increase the salary of that employee by 5000 in the given table. It is then called to increase salaries for employees 'LUCY' and 'JADE' in the Emp_Test table.

Uploaded by

Rakesh Maher
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

1. create table Emp_Test (


2. Emp_Id varchar(5) PRIMARY KEY,
3. Emp_Name varchar(20),
4. Dept_No number(5),
5. Hire_Date date,
6. Job_Id number(5),
7. Salary number(10,2),
8. Mgr_No varchar(5),
9. Comm number(8,2)
10. );
11.
12. insert into Emp_Test(Emp_Id ,Emp_Name,Dept_No,Hire_Date,Job_Id ,Salary,Mgr_No,Comm)
13. values('E01','JADE',10,'24-FEB-2019',5,60000.50,'E04',3000);
14.
15. insert into Emp_Test(Emp_Id ,Emp_Name,Dept_No,Hire_Date,Job_Id ,Salary,Mgr_No,Comm)
16. values('E02','LUCY',30,'10-DEC-2019',6,30000.75,'E01',4000);
17.
18. insert into Emp_Test(Emp_Id ,Emp_Name,Dept_No,Hire_Date,Job_Id ,Salary,Mgr_No,Comm)
19. values('E03','JOY',10,'1-MAR-2015',5,100000,'E04',2000);
20.
21. insert into Emp_Test(Emp_Id ,Emp_Name,Dept_No,Hire_Date,Job_Id ,Salary)
22. values('E04','ROSE',20,'12-JUN-2017',5,110000.20);
23.
24. insert into Emp_Test(Emp_Id ,Emp_Name,Dept_No,Hire_Date,Job_Id ,Salary,Mgr_No)
25. values('E05','VINI',20,'19-DEC-2020',3,90000,'E02');
26.
27. SELECT * FROM Emp_Test;
28.

OUTPUT-
2.

1. DECLARE
2. CURSOR C1 IS SELECT * FROM (SELECT * FROM Emp_Test ORDER BY SALARY) WHERE ROWNUM<=3;
3. C Emp_Test%ROWTYPE;
4. BEGIN
5. OPEN C1;
6. LOOP
7. FETCH C1 INTO C;
8. EXIT WHEN C1%NOTFOUND;
9. DBMS_OUTPUT.put_line(C.EMP_NAME || ' EARNS ' || C.SALARY);
10. END LOOP;
11. CLOSE C1;
12. END;
13.

OUTPUT-
3.

1. CREATE OR REPLACE PROCEDURE SHOW_EMPS(


2. Dept_No_In IN Emp_Test.Dept_No%TYPE
3. )
4. IS
5. TYPE EMP_COLS_RT IS RECORD(
6. EMPLOYEE_NAME Emp_Test.Emp_Name%TYPE,
7. EMPLOYEE_SALARY Emp_Test.Salary%TYPE,
8. EMPLOYEE_MANAGER Emp_Test.Mgr_No%TYPE
9. );
10. TYPE EMPLOYEE_INFO_T IS TABLE OF EMP_COLS_RT;
11. L_EMPLOYEE EMPLOYEE_INFO_T;
12. BEGIN
13. SELECT Emp_Name,Salary,Mgr_No
14. BULK COLLECT INTO L_EMPLOYEE
15. FROM Emp_Test
16. WHERE Dept_No = Dept_No_In;
17.
18. FOR INDX IN 1 .. L_EMPLOYEE.COUNT
19. LOOP
20. DBMS_OUTPUT.PUT_LINE(
21. L_EMPLOYEE(INDX).EMPLOYEE_NAME || ' MAKES ' || L_EMPLOYEE(INDX).EMPLOYEE_SALARY
|| ' whose manager number is' || L_EMPLOYEE(INDX).EMPLOYEE_MANAGER
22. );
23. END LOOP;
24. END;
25.
26. BEGIN
27. SHOW_EMPS(20);
28. SHOW_EMPS(30);
29. END;
30.

OUTPUT-
4.

1. CREATE OR REPLACE PROCEDURE INCR_SAL(table_in IN VARCHAR, empName_in IN VARCHAR)


2. AS
3. BEGIN
4. EXECUTE IMMEDIATE 'UPDATE ' || table_in || ' SET SALARY = SALARY + 5000 ' || ' where
Emp_Name = :empName_in' using empName_in;
5. END;
6.
7. BEGIN
8. INCR_SAL('Emp_Test','LUCY');
9. INCR_SAL('Emp_Test','JADE');
10. END;
11.
12. SELECT * FROM Emp_Test;
13.

OUTPUT-

You might also like