Lab Practice 4
Lab Practice 4
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;
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
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