Professional Documents
Culture Documents
Oracle
Oracle
Oracle
SQL SQL*Plus
A language An environment
ANSI-standard Oracle proprietary
Keywords cannot be abbreviated Keywords can be abbreviated
Statements manipulate data and table Commands do not allow manipulation of
definitions in the database values in the database
15 You are the DBA. You are creating many users who require the same system privileges.
What should you use to make your job easier?
Create a role containing the system privileges and grant the role to the users.
Page 2
Part II: Display the information as below:
1. Display the employee last_name,job_id and start_date of employees hired between 2010
and 2014 order by start_date in a week and format as (Day the month of Year)
Answer:
SELECT LAST_NAME,JOB_ID,TO_CHAR(HIRE_DATE,'DD MONTH YYYY')
START_DATE FROM EMPLOYEES
WHERE TO_CHAR(HIRE_DATE,'YYYY')IN (2010,2014)
2. Write a query to display the last name, department number and department name for all
the employees who work in Toronto
5. Create an anniversary overview based on the hire date of the employees. Sort the
anniversaries in ascending order.
Answer:
SELECT last_name,TO_CHAR(hire_date,Month DD) Birthday FROM employees
ORDER BY TO_CHAR(hire_date,DDD);
6. Show the name,salaries, and the number of dollar (in thousand) that all employees earn.
Answer:
SELECT last_name,salary,TRUNC(salary,-3)/1000 Thousands FROM employees;
7. Show all employees who have managers with a salary higher than $15,000.Showthe
following data: employee name,manager name, manager salary, and salary grade of the
manager.
Answer:
SELECT e.last_name,m.last_name manager,m.salary,j.grade_level
FROM employees e, employees m,job_grades j WHERE e.manager_id=m.employee_id AND
m.salary BETWEEN j.lowest_sal AND j.highest_sal AND m.salary>15000
8. Show all employees who were hired on the day of the week on which the highest number
of employees were hired.
9. SELECT last_name,TO_CHAR(hire_date,Day)Day FROM employees
Page 3
WHERE TO_CHAR(hire_date,Day)=(SELECT TO_CHAR(hire_date,Day)
HAVING COUNT(*)=(SELECT MAX(COUNT(*)) FROM Employees GROUP BY
TO_CHAR(hire_date,Day)))
10. Write a query to display the top three earners in the employees table. Display their last
names and salaries.
Answer:
SELECT last_name,salary FROM employees e WHERE 3>
(SELECT count(*) FROM employees WHERE e.salary<salary);
11. Write a query to display the last names,month of the date of join, and hire date of those
employees who have joined in the month of January,iresspective of the year of join.
SELECT last_name,EXTRACT(MONTH FROM HIRE_DATE),HIRE_DATE FROM
employees WHERE EXTRACT(MONTH FROM HIRE_DATE)=1
12. Display the employee number,last name, and salary of all employees who earn more than
the average salary. Sort the results in order of ascending salary.
SELECT employee_id,last_name,salary FROM employees WHERE salary>(SELECT
AVG(salary) FROM employees) ORDER By salary;
13. Display the last name,hire date, and day of the week on which the employee started.
Label the column as DAY. Order the results by the Day of the week, starting with
Monday.
SELECT last_name,hire_date,TO_CHAR(hire_date),DAY) DAY FROM employees
ORDER BY TO_CHAR(hire_date -1,d);
Page 4