Asg12 2
Asg12 2
Query
A. Consider the schema for Company Database:
DLOCATION (DNo,DLoc)
1. Make a list of all project numbers for projects that involve an employee
whose last name is ‘Scott’, either as a worker or as a manager of the
department that controls the project.
2. Show the resulting salaries if every employee working on the ‘IoT’ project
is given a 10 percent raise.
3. Find the sum of the salaries of all employees of the ‘Accounts’
department, as well as the maximum salary, the minimum salary, and the
average salary in this department
4. Retrieve the name of each employee who works on all the projects
controlled by department number 5 (use NOT EXISTS operator).
5. For each department that has more than five employees, retrieve the
department number and the number of its employees who are making
more than Rs. 6,00,000.
Answer
Consider the schema for Company Database:
Name VARCHAR2(50),
Address VARCHAR2(100),
Sex CHAR(1),
SuperSSN VARCHAR2(10),
DNo NUMBER
);
desc EMPLOYEE
INSERT INTO EMPLOYEE VALUES ('111', 'John Scott', 'Delhi', 'M', 900000, NULL, 1);
INSERT INTO EMPLOYEE VALUES ('112', 'Sara Khan', 'Mumbai', 'F', 850000, '111', 2);
INSERT INTO EMPLOYEE VALUES ('113', 'Mike Smith', 'Pune', 'M', 600000, '112', 3);
INSERT INTO EMPLOYEE VALUES ('114', 'Rita Sharma', 'Chennai', 'F', 750000, '113', 3);
INSERT INTO EMPLOYEE VALUES ('115', 'Scott Wilson', 'Bangalore', 'M', 950000, '111', 5);
INSERT INTO EMPLOYEE VALUES ('116', 'Aman Verma', 'Kolkata', 'M', 500000, '114', 5);
INSERT INTO EMPLOYEE VALUES ('117', 'Sneha Roy', 'Hyderabad', 'F', 700000, '115', 5);
DName VARCHAR2(50),
MgrSSN VARCHAR2(10),
MgrStartDate DATE
);
desc DEPARTMENT
DLOCATION (DNo,DLoc)
DNo NUMBER,
DLoc VARCHAR2(50),
);
desc DLOCATION
INSERT INTO DLOCATION VALUES (1, 'Delhi');
PName VARCHAR2(50),
PLocation VARCHAR2(50),
DNo NUMBER
);
desc PROJECT
SSN VARCHAR2(10),
PNo NUMBER,
Hours NUMBER(5,2),
);
desc WORKS_ON
FROM PROJECT P
WHERE P.DNo IN (
SELECT D.DNo
FROM DEPARTMENT D
);
2. Show the resulting salaries if every employee working on the ‘IoT’
project is given a 10 percent raise.
FROM EMPLOYEE E
SELECT
SUM(E.Salary) AS Total_Salary,
MAX(E.Salary) AS Max_Salary,
MIN(E.Salary) AS Min_Salary,
AVG(E.Salary) AS Avg_Salary
FROM EMPLOYEE E
SELECT E.Name
FROM EMPLOYEE E
SELECT P.PNo
FROM PROJECT P
WHERE P.DNo = 5
MINUS
SELECT W.PNo
FROM WORKS_ON W
);
5. For each department that has more than five employees, retrieve the
department number and the number of its employees who are making
more than Rs. 6,00,000.
FROM EMPLOYEE E
GROUP BY E.DNo
num1 IN NUMBER,
num2 IN NUMBER
) IS
a NUMBER := num1;
b NUMBER := num2;
temp NUMBER;
BEGIN
WHILE b != 0 LOOP
temp := b;
b := MOD(a, b);
a := temp;
END LOOP;
DBMS_OUTPUT.PUT_LINE('The GCD of ' || num1 || ' and ' || num2 || ' is: ' || a);
END;
/
SET SERVEROUTPUT ON;
BEGIN
find_gcd(36, 60);
END;
/
Write a program in PL/SQL to create a cursor displays the name and salary of each
employee in the EMPLOYEES table whose salary is less than that specified by a passed-in
parameter value.
v_name EMPLOYEE.Name%TYPE;
v_salary EMPLOYEE.Salary%TYPE;
BEGIN
OPEN emp_cursor(p_max_salary);
LOOP
END LOOP;
CLOSE emp_cursor;
END;
/
BEGIN
get_low_salary_employees(60000);
END;
/