Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Database Management System

(DBMS – 204)

Experiment # 03

Single Row Functions

Student Name: Maria Pasha


Roll Number: SE-19005

Maximum Marks Performance = 05 Viva = 05 Total = 10


Marks Obtained
Remarks (if any)

Experiment evaluated by

Instructor Name: Engr. Adiba Jafar

Signature and Date:


Practice 2, Part 1
Write a query that displays the employee’s 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 an appropriate label. Sort the results by the employees’ names.
SQL QUERY: select initcap(ename) "Employee" ,length(ename) "Name Length" from scott.emp where
ename like 'J%' or ename like 'A%' or ename like 'M%' order by ename;

Practice 2, Part 2
For each employee, display the employee’s 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.
SQL QUERY:
Select ename, hiredate,round(months_between(sysdate,hiredate)) as "MONTHS WORKED" from scott.emp
order by "MONTHS WORKED";

Practice 3, Part 2
Write a query that produces the following for each employee: < employee name> earns <salary> monthly but
wants <3 times salary >. Label the column Dream Salaries . If you have time, complete the following
exercises:
Solution Query: select ename||' earns '||sal||' monthly but wants '||sal * 3 as "dream salary" from scott.emp;
1. Write a query that displays the employee’s 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 an appropriate label. Sort the results by the employees’ last names.

2. For each employee, display the employee’s 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.
3. 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 . If you have time, complete
the following

4. Create a 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
5. 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
similar to “Monday, the Thirty-First of July, 2000.”

6. Display the 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.
7. Create a query that displays the employees’ names and commission amounts. If an
employee does not earn commission, put “No Commission.” Label the column
COMMISSION.

8. Create a query that displays the employees’ 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.
9. Using the DECODE function, write a query that displays the grade of all employee s based
on the value of the column JOB , as per the following data: A president B manager C
analyst D Salesman E CLERK F None of the above 0

You might also like