0% found this document useful (0 votes)
9 views

Lecture 03

oracle database slide notes

Uploaded by

Irfan Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Lecture 03

oracle database slide notes

Uploaded by

Irfan Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Lecture 03

1) Write a query to display the current date. Label the column Date.

SELECT SYSDATE

FROM DUAL;

2) For each employee, display the employee number, last_name, salary, and
salary increased by 15% and expressed as a whole number. Label the column New
Salary. Place your SQL statement in a text file named lab3_2.sql.

SELECT employee_id,last_name,salary,

(salary*0.15)+salary "New Salary"

FROM employees;

3) Run your query in the file lab3_2.sql.

4) Modify your query lab3_2.sql to add a column that subtracts the old salary
from the new salary. Label the column Increase. Save the contents of the file as
lab3_4.sql. Run the revised query.
SELECT employee_id,last_name,salary,

(salary*0.15)+salary "New_Salary",

((salary*0.15)+salary) - salary Increase

FROM employees;

5) Write a query that displays the employee’s last names with the first letter
capitalized and all other letters lowercase, and the length of the names, for all
employees whose name starts with J, A, or M. Give each column appropriate
label. Sort the results by the employees’ last names.

SELECT INITCAP(last_name) Name , LENGTH(last_name) Length

from employees

WHERE last_name like 'A%' OR last_name like 'M%' OR last_name like 'J%'

ORDER BY last_name ;
6) For each employee, display the employee’s last name, and calculate the
number of months between today and the date the employee was hired. Label
the column MONTHS_WORKED. Order your results by the number of months
employed. Round the number of months up to the closest whole number.

Note: Your results will differ.

SELECT last_name, ROUND(MONTHS_BETWEEN (SYSDATE,hire_date),0) Worked

FROM employees

ORDER BY Worked;

7) Write a query that produces the following for each employee:


<employee last name> earns <salary> monthly but wants <3 times salary>. Label
the column Dream Salaries.

SELECT CONCAT (CONCAT( last_name ,' earns $' ) ,CONCAT(salary,' mon,thly but
wants $')),concat(salary*3, ' ') "Dream Salaries"

FROM employees;
If you have time, complete the following exercises:

8. query to display the last name and salary for all employees. Format the salary
to be 15
characters long, left-padded with $. Label the column SALARY.

SELECT last_name ,LPAD(salary,15,'*') as salary

FROM EMPLOYEES;
9. Display each employee’s last name, hire date, and salary review date, which is the first Monday after
six months of service. Label the column REVIEW. Format the dates to appear in the format similar to
“Monday, the Thirty-First of July, 2000.”

*************
10. Display the last name, hire date, and day of the week on which the employee started. Label
the column DAY. Order the results by the day of the week starting with Monday.

SELECT last_name, hire_date , NEXT_DAY(HIRE_DATE,'MONDAY') as day

FROM employees;
If you want an extra challenge, complete the following exercises:

11. Create a query that displays the employees’ last names and commission amounts. If an employee
does not earn commission, put “No Commission.” Label the column COMM.

SELECT last_name,comiistion_pct,

12.Create a query that displays the employees’ last names and indicates the amounts of their annual
salaries with asterisks. Each asterisk signifies a thousand dollars. Sort the data in descending order of
salary. Label the column EMPLOYEES_AND_THEIR_SALARIES.

You might also like