Introduction Oracle SQL and Pl SQL
Introduction Oracle SQL and Pl SQL
Module 1/Day 1
SELECT Statement:
1. List tables in your schema and check for existence of DEPT, EMP and SALGERADE tables
2. If these tables do NOT exists – execute the script in the embedded DemoBld.SQL file to create
and populate the tables .
7. List employee number, name and salary from employee table where salary is > 3000
11. List employees in ascending order of job within descending order of deptno
14. List name, salary and annual salary in the descending order of annual salary – annual salary is a
computed column – SAL * 12
15. List employees whose salary is not in the range of 2000 and 3000
16. List name and the deptno for all employees who are NOT members of departments 10 and 20
19. List employees in ascending order of COMM and note how NULLs are sorted
25. List total/sum, maximum, minimum, average of salary from employee table
29. List department wise total salary for deptno 10 and 20 only
30. List department wise total salary where total salary is > 6000
31. SELECT COUNT(*), COUNT(COMM) FROM EMP; - explain why the two counts are different
Sub Queries:
5. List employees show salary is > the max salary of all employees in deptno 30
6. List all employees whose deptno and Job are same as that of employee with empno 7788.
9. List all employees who earn(salary) more than the average salary in their own department
10. List employees whose salary is greater than their manager’s salary
11. List details of departments from DEPT table for which there are no employees in EMP table
Joins:
1. List employee name, department number and their corresponding department name by joining
EMP and DEPT tables
2. List employee name and their manager name by joining EMP table to itself
3. List employee name, department name and their grade by joining EMP, DEPT and SALGRADE
tables
4. List employees who work in ‘Research’ department by joining EMP and DEPT tables
5. List all rows from EMP table and only the matching rows from DEPT table – LEFT OUTER JOIN
6. List only matching rows from EMP table and all rows from DEPT table – RIGTH OUTER JOIN
7. Write a query to perform full outer join between EMP and DEPT tables
8. List employee name, their manager name and their manager’s manager name
DDL
1. Create DEPARTMENT table with the following columns with appropriate data type and width
a) Deptno PK
b) Danme
c) Location
2. Create EMPLOYEE table with the following columns with appropriate data type and width
a. empno PK
c. designation
d. sex
f. Date of joining
DML
1. Insert at least 5 valid rows into DEPARTMENT table and commit the changes
2. Insert at least 15 valid rows in EMPLOYEE table and commit the changes
3. Update basic_salary by 10% for employees in deptno 10 and 20 and commit the changes
4. Update basic_salary and commission by 10% and 2% for all employees for whom commission is
currently applicable and commit the changes
5. Update the designation of given employee to MANAGER based of given employee number and
commit the changes.
6. Delete employees joined before a given year and commit changes
7. Delete all rows from employee tables.
8. Query employee table
9. ROLLBACK
10. Query employee table
11. Delete all rows from employee tables permanently using appropriate DDL command
1. Create a procedure named DISP_EMP_DETAILS with 3 parameters one [ie. iEmpNo ] is an “IN”
mode and other two are [ie. sGrade and sSalary] “OUT” mode parameters. The procedure should
retrieve the Grade (this is column of SALGRADE table) and Salary for the specified employee number
[ie. iEmpNo ] by joining EMP and SALGRADE table and assign the retrieved values to the “OUT”
mode parameters.
Note.:
It should display an appropriate error message if the specified employee number
does not exist in “Employee” table.
Call the created procedure using Bind variable and print the details.
2. Create a procedure named DISPLAY_RECORDS which accepts the P_JOB as a parameter and display
all the employees (empno, sal, deptno, job) from the “EMP” table matching the given P_JOB in the
following format :-