Oracle SQL Excercises

Department Employee Address Tables

Exercise 1 (Retrieving Data)

  1. Select employee numbers, employee names from employee table.

  2. Select employee numbers grater than 1010.

  3. Select employee number, employee name who draws more than 2000 as the Salary.

  4. Select employee number, sal, comm for department 20.

  5. Select employee names who were getting salary greater than 1500.

  6. Select all the employees whose job = 'CLERK'.

  7. Select all the employees whose job = 'CLERK' and salary > 2000.

  8. Select employee number, name who works in deptno 30 and name starts with 'K

  9. Select all the columns from employee table.

  10. Select employee number, name, sal, comm who works in deptno 10, salary greater than 2000 and comm less than 250.

Exercise 2 (Retrieving Data)

  1. Select employee names who born in 1971.

  2. Select employee names who works in deptno 20 and born in 1972.

  3. Select employee names who born between 1950 and 1974.

  4. Select empno, employee name, addition of salary and commission for deptno 40.

  5. Select number of records in employee table.

  6. Select number of records in deptno table where deptno is less than 20.

  7. Select all the departments in Dallas.

  8. Select all the departments where department name starts with A.

  9. Select different department numbers in employee table.

  10. Select number of rows in employee address who lives in Dallas.

Exercise 3 (Retrieving Data)

  1. Select maximum, minimum salary in employee table.

  2. Select minimum salary,commission in employee table for deptno 20.

  3. Select employee number, employee name, department number whose sum of salary and commission greater than 2500.

  4. Select employee number, employee name, employee age from employee table.

  5. Selectemployee number , employee name born in the month of july.

  6. Select employee name ,DOB in the format of "2nd of july 1997" for deptno 10 and 20.

  7. Display employee names in lower case whose salary is greater than 2000 and less than 2800.

  8. Select the number of employees who has no commission .

  9. Select employee name whose job is Manager or Clerk and Salary greater than 1000 and commission greater than 100 and deptno is either 10 or 20.

  10. Select employee names in an alphabetical order.

Exercise 4 (Functions)

  1. Display current date and 78 days after.

  2. Display the current date in the following fashion. Today's date is : Jan 4 1998.

  3. Display Employee name and Job information from employee in the following fashion. SMITH Works as CLERK.

  4. Display all the information from department table where second character of city name is 'A'.

  5. Display rowid, employee number from employee table.

  6. Display rowid, row number, deptno from department table.

  7. Display the last date in Feb-97

  8. Display logged on user name in the following fashion. Current User Name is : SCOTT

  9. Display 'YOU ARE GOOD IN SQL' text as 'You Are Good In Sql' in a Select statement.

  10. Display current date and 78 days before.

Exercise 5 (Simple Joins)

  1. Display employee number, employee name, department name, location from employee and department tables.

  2. Display employee number, employee name, salary + comm as TOTAL, location from employee and department tables.

  3. Display employee name, location from employee and department tables.

  4. Diplay employee name, department name, job from employee and department tables who job is CLERK.

  5. Display employee name, deptno, dname from employee and department table where location is DALLAS.

  6. Display employee number, name, address and city from employee, employee address tables.

  7. Display employee nmae, address from employee and employee address tables who lives in zip code 75039

  8. Display employee name, department name, location who were getting comm as null.

  9. Display first 3 characters of employee name, job, sal, comm, location from employee and department tables who works in department 20 or 30, salary should be more than 1000 comm as not null.

  10. Display location, department name, length of location, length of department name for employee numbers 1001, 1008, 1009.

Exercise 6 (Group By Clause)

  1. Display deptno, number of employee works in each department.

  2. Display job, number of employees works in each category.

  3. Display job and averge salary paid for each jobs in the company.

  4. Display location and sum of the salary spending for employees on that location respectively.

  5. Select minimum salary, maximum salary in each department.

  6. Select department number, dname, average salary for each department.

  7. Select job, number of employees working in that job, maximum and minimum salary for each job.

  8. Select department number, name where atleast 3 employees works.

  9. Select department name, location where the average salary in each department more than 1600.

  10. Select department name, job and sum of salary by each job with in the department.

Exercise 7 (Use SQL Functions )

  1. Display the following text in lowercase ‘DISPLAY EXAMPLE IN LOWERCASE’
  2. Display the following text in uppercase ‘you are great’.
  3. Write a select statement to add 123 and 786.
  4. What is the length of ‘CURRENT’ string.
  5. Display the current username.
  6. Display ‘DOCTOR’ from ‘JOHN IS A DOCTOR’ string.
  7. Display Day of 'July-10-1998'
  8. Display number of days till today from your date of birth.
  9. Display the date after 18 months from today.
  10. Display employee information if employee id is an even number

Exercise 8 (Date functions from Dual Table)

  1. Display Current date
  2. Display Current Time.
  3. Display current user name.
  4. Display Current date in July 3 1997 format
  5. Display Current date and the date after 78 days.
  6. Display Current date, day, 70 days after current date and its day also.
  7. Display the months between ‘JAN-10-65’ and ‘JUN-23-98’ take the input in specified format.
  8. Display the current date as Today’s date is : current date from system.
  9. Display Current date, time and user name.
  10. Display the day like Sunday or what for this date ‘July 4 1998’

Exercise 9 (Data Control Language 1)

  1. Create a user named JOHN.
  2. Create a Role named ‘DEPT_MANAGERS’
  3. Grant Select, Update permissions on Employee table to DEPT_MANGAGERS role.
  4. Create a Role named ‘CHIEF_MANAGERS’.
  5. Grant Select, Update, Delete, Insert permissions on Employee to CHIEF_MANAGERS.
  6. Grant DEPT_MANAGERS role to SCOTT.
  7. Grant CHIEF_MANAGERS role to JHON.
  8. Revoke update on permission on Salary column of Employee table from DEPT_MANAGERS.
  9. Revoke update on employee from DEPT_MANAGERS
  10. Assign DEPT_MANAGERS role to everyone in the database.

Exercise 10 (Data Dictionary I)

  1. Select table names created by SCOTT.
  2. Select view names created by SCOTT.
  3. Select trigger names on EMP table.
  4. Display all indexes on DEPT table.
  5. Display all the user names from oracle database.
  6. Select table owner, names created by SCOTT or JHON
  7. Select all the sequences created by current user.
  8. Display trigger’s text for ‘EMP_INSERT_TR’ trigger.
  9. Display all the data dictionary objects which starts with ‘USER’.
  10. Display all the roles available in the database.

Exercise 11 (Data DictionaryII)

  1. Display synonyms created by SCOTT.
  2. Display all the constraints defined for employee table.
  3. Display all the check constraints defined for employee table.
  4. Display procedure text for ‘SP_INSERTEMP’.
  5. Display all procedures available in the database.
  6. Display all the functions created by SCOTT.
  7. Display function text for ‘FN_CHECKEMP’.
  8. Display Sequences created by SCOTT.
  9. Display different Tablespaces available in the database.
  10. Display tables in 'USER_DATA' tablespace.