0% found this document useful (0 votes)
57 views3 pages

Lab Practice 4

This document contains 10 SQL queries that were executed as part of a lab practice. The queries: 1) Display the current date. 2) Display employee number, last name, salary and salary increased by 15.5% along with the increase amount. 3) Calculate months of employment for each employee. 4) Display initial capped last names and length that start with J, A or M. 5) Format salaries with left-padded $ symbols. 6) Display last names and commissions or 0 if none. 7) Display partial last names with asterisks representing thousands of salary amount in descending order. 8) Assign grades to jobs using DECODE. 9) Rewrite previous using CASE.

Uploaded by

Jie You
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)
57 views3 pages

Lab Practice 4

This document contains 10 SQL queries that were executed as part of a lab practice. The queries: 1) Display the current date. 2) Display employee number, last name, salary and salary increased by 15.5% along with the increase amount. 3) Calculate months of employment for each employee. 4) Display initial capped last names and length that start with J, A or M. 5) Format salaries with left-padded $ symbols. 6) Display last names and commissions or 0 if none. 7) Display partial last names with asterisks representing thousands of salary amount in descending order. 8) Assign grades to jobs using DECODE. 9) Rewrite previous using CASE.

Uploaded by

Jie You
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/ 3

Lab Practice 4 (13.03.

2014)
1. Write a query to display the current date. Label the column Date.
select SYSDATE "date"
from dual;
2. The HR department needs a report to display the employee number,
last name, salary and salary increased by 15.5% (expressed as a whole
number) for each employee. Label the column New Salary. Hint : use
Round Function

select

employee_id,last_name,Round(salary*1.155)

"New

Salary"
from employees;
3. Add a column that subtracts the old salary from the new salary. Label
the column Increase.
select employee_id,last_name,Round(salary*1.155) "New
Salary",Round((salary*1.555)-salary)"Increase"
from employees;
4. Write a query that displays the last name (with the first letter
uppercase and all other letters lowercase) and the length of the last
name for all employees whose name starts with the letters J, A or M.
Give each column an 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'J%'
or last_name like'A%'
or last_name like'M%'
order by last_name;

5. The HR department wants to find the length of employment for each


employee. For each employee, display the last name and calculate the
number of months between today and the date on which 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.
select
last_name,Round((SYSDATE-hire_date)/30)
"MONTHS_WORKED"
from employees
order by Round((SYSDATE-hire_date)/30);

6. Create a query to display the last name and salary for all employees.
Format the salary to be 15 characters long, left-padded with the $
symbol. Label the column SALARY.
select last_name,LPAD(salary,15,'$') "SALARY"
from employees;
7. Create

a query that displays the employees last names and

commission amounts. If an employee does not earn commission, show


0. Label the column COMM. Hint : use NVL
select last_name,NVL(commission_pct,'0') "COMM"
from employees;

8. Create a query that displays the first eight characters of the

employees last names and indicates the amounts of their salaries with
asterisks. Each asterisk signifies a thousand dollars. Sort the data in
descending

order

of

salary.

Label

the

column

EMPLOYEES_AND_THEIR_SALARIES.

select SUBSTR(LAST_NAME,1,8)
| |lpad('' ,(salary/1000)+1,'*')"EMPLOYEE_AND_THEIR_SALARIES"
FROM EMPLOYEES
ORDER BY salary DESC

9. Using the DECODE function, write a query that displays the grade of all
employees based on the value of the column JOB_ID, using the
following data :
Job
AD_PRES
ST_MAN
IT_PROG

Grade
A
B
C

SA_REP
D
ST_CLERK
E
None of the above 0
select job_id,last_name ,
decode(job_id,'AD_PRES','A',
'ST_MAN', 'B',
'IT_PROG','C',
'SA_REP', 'D',
'ST_CLERK' , 'E','0' )"Grade"
from employee
10. Rewrite the statement in the preceding exercise using the CASE
syntax.
select job_id,last_name ,
case job_id when'AD_PRES' then'A'
when 'ST_MAN' then 'B'
when 'IT_PROG' then 'C'
when 'SA_REP' then 'D'
when 'ST_CLERK'then 'E'
else '0' end"Grade"
from employee

You might also like