HR Oracle Database
HR Oracle Database
Oracle SQL
1. Display employees who joined in 2000 and doing job that has maximum salary more
than 10000.
Display departments where the name of the manager is MICHAEL.
3.Display jobs where the minimum salary is less than salary of employee 105.
7. Display job id, department id and sum of salary by including al possible dimensions.
8. Display employee name and job title of jobs where salary of employee is between
minimum and maximum salary for job.
9. Display how many employees have commission percentage and how many do not have.
10. Display first name, job title, department name of employees who joined on 28th Feb.
11. Display details of jobs where the minimum salary is greater than 10000.
12. Display the first name and join date of the employees who joined between 2002 and 2005.
13. Display first name and join date of the employees who is either IT Programmer or
Sales Man.
[email protected] pg. 1
14. Display employees who joined after 1st January 2008.
17. Display job Title, the difference between minimum and maximum salaries for jobs
with max salary in the range 10000 to 20000.
18. Display first name, salary, and round the salary to thousands.
19. Display details of jobs in the descending order of the title.
20. Display employees where the first name or last name starts with S.
23. Display first name and date of first salary of the employees.
26. Display first name and last name after converting the first letter of each name to upper
case and the rest to lower case.
27. Display the first word in job title.
28. Display the length of first name for employees where last name contain character ‘b’ after
3rd position.
29. Display first name in upper case and email address in lower case for employees where the
first name and email address are same irrespective of the case.
30. Display employees who joined in the current year.
31. Display the number of days between system date and 1st January 2011.
32. Display how many employees joined in each month of the current year.
33. Display manager ID and number of employees managed by the manager.
34. Display employee ID and the date on which he ended his previous job.
35. Display number of employees joined after 15th of the month.
36. Display the country ID and number of cities we have in the country.
37. Display average salary of employees in each department who have commission
percentage.
38. Display job ID, number of employees, sum of salary, and difference between highest
salary and lowest salary of the employees of the job.
39. Display job ID for jobs with average salary more than 10000.
40. Display years in which more than 10 employees joined.
[email protected] pg. 2
41. Display departments in which more than five employees have commission percentage.
42. Display employee ID for employees who did more than one job in the past
. 43. Display job ID of jobs that were done by more than 3 employees for more than 100
days.
45. Display departments where any manager is managing more than 5 employees.
46. Change salary of employee 115 to 8000 if the existing salary is less than 6000
. 47. Insert a new employee into employees with all the required details. 48. Delete
department 20.
49. Change job ID of employee 110 to IT_PROG if the employee belongs to department 10
and the existing job ID does not start with IT.
50. Insert a row into departments table with manager ID 120 and location ID in any
location ID for city Tokyo.
51. Display department name and number of employees in the department. 52. Display job
title, employee ID, number of days between ending date and starting date for all jobs in
department 30 from job history.
53. Display department name and manager first name.
54. Display department name, manager name, and city.
55. Display country name, city, and department name.
56. Display job title, department name, employee last name, starting date for all jobs from 2000
to 2005.
57. Display job title and average salary of employees
58. Display job title, employee name, and the difference between maximum salary for the job
and salary of the employee.
59. Display last name, job title of employees who have commission percentage and belongs to
department 30.
60. Display details of jobs that were done by any employee who is currently drawing more than
15000 of salary.
61. Display department name, manager name, and salary of the manager for all
managers whose experience is more than 5 years.
62. Display employee name if the employee joined before his manager. 63. Display
employee name, job title for the jobs employee did in the past where the job was done less
than six months.
64. Display employee name and country in which he is working.
65. Display department name, average salary and number of employees with commission
[email protected] pg. 3
within the department.
66. Display the month in which more than 5 employees joined in any department located in
Sydney.
67. Display details of departments in which the maximum salary is more than 10000. 68.
Display details of departments managed by ‘Smith’.
69. Display jobs into which employees joined in the current year.
70. Display employees who did not do any job in the past.
71. Display job title and average salary for employees who did a job in the past. 72. Display
country name, city, and number of departments where department has more than 5
employees.
73. Display details of manager who manages more than 5 employees. 74. Display employee
name, job title, start date, and end date of past jobs of all employees with commission
percentage null.
75. Display the departments into which no employee joined in last two years. 76. Display the
details of departments in which the max salary is greater than 10000 for employees who did a
job in the past.
77. Display details of current job for employees who worked as IT Programmers in the
past.
78. Display the details of employees drawing the highest salary in the department. 79.
Display the city of employee whose employee ID is 105.
80. Display third highest salary of all employees
Oracle PL/SQL
1. Write a program to interchange the salaries of employee 120 and 122. 2. Increase the salary
of employee 115 based on the following conditions: If experience is more than 10 years,
increase salary by 20% If experience is greater than 5 years, increase salary by 10% Otherwise
5% Case by Expression.
3. Change commission percentage as follows for employee with ID = 150. If salary is more
than 10000 then commission is 0.4%, if Salary is less than 10000 but experience is more than
10 years then 0.35%, if salary is less than 3000 then commission is 0.25%. In the remaining
cases commission is 0.15%.
4. Find out the name of the employee and name of the department for the employee who is
managing for employee 103.
5. Display missing employee IDs.
6. Display the year in which maximum number of employees joined along with how many
[email protected] pg. 4
joined in each month in that year.
7. Change salary of employee 130 to the salary of the employee with first name ‘Joe’. If Joe is
not found then take average salary of all employees. If more than one employee with first
name ‘Joe’ is found then take the least salary of the employees with first name Joe.
8. Display Job Title and Name of the Employee who joined the job first day. 9.
Display 5th and 10th employees in Employees table.
10. Update salary of an employee based on department and commission percentage. If
department is 40 increase salary by 10%. If department is 70 then 15%, if commission is
more than .3% then 5% otherwise 10%.
11. Create a function that takes department ID and returns the name of the manager of the
department.
12. Create a function that takes employee ID and return the number of jobs done by the
employee in the past.
13. Create a procedure that takes department ID and changes the manager ID for the
department to the employee in the department with highest salary. (Use Exceptions). 14.
Create a function that takes a manager ID and return the names of employees who report to
this manager. The names must be returned as a string with comma separating names.
15. Ensure no changes can be made to EMPLOYEES table before 6am and after 10pm in a
day.
16. Create a Trigger to ensure the salary of the employee is not decreased. 17. Create a trigger to
ensure the employee and manager belongs to the same department. Note: This trigger needs to
read the row that is being modified, which causes mutating problem.
The solution to mutating problem is explained at Work around for mutating problem in
Oracle Triggers. Please check it out.
18. Whenever the job is changed for an employee write the following details into job
history. Employee ID, old job ID, old department ID, hire date of the employee for start
date, system date for end date. But if a row is already present for employee job history then
the start date should be the end date of that row +1.
Note: Before testing the above trigger, you need to disable UPDATE_JOB_HISTORY
trigger, which is already present in HR account, as it does the same.