0% found this document useful (0 votes)
11 views7 pages

23 55566 3 - LabTask02

database
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)
11 views7 pages

23 55566 3 - LabTask02

database
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/ 7

American International University-Bangladesh

(AIUB)
Introduction to Database
Midterm Lab Tasks-02
1) Write a query to display the current date. Label the column Date.
Ans:
select sysdate as "Date" from dual

2) Display the employee number, name, salary, and salary increase by 15% expressed as a
whole number. Label the column New Salary.
Ans.: select empno, ename, sal, round(sal*.15)+sal as "New Salary" from emp

3) Modify your previous query to add a column that will subtract the old salary from the new
salary. Label the column Increase. Rerun your query.
Ans:
select empno, ename, sal, round(sal*.15)+sal as "New Salary" , round(sal*.15)+sal -sal as
"Increase" from emp
4) Display the employee’s 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 “Sunday, the Seventh of September, 1981.”
Ans:
select ename, hiredate,to_char(next_day(add_months(hiredate,6),'MONDAY'), 'Day, "the"
DD "of" Month, YYYY') as "REVIEW" from emp

5) For each employee display the employee 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.
Ans:
select ename, round(months_between(sysdate,hiredate)) as "MONTHS_WORKED" from
emp order by round(months_between(sysdate,hiredate))

6) 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.
Ans:
select ename||' earns '||sal||' monthly but wants '||3*sal as " Dream Salaries" from emp;
7) Write a query that will display the employee’s name with the first letter capitalized and all
other letters lowercase and the length of their name, for all employees whose name starts
with J, A, or M. Give each column an appropriate label.
Ans:
select initcap(ename) as "Name", length(ename) as "Name Length" from emp
where substr(ename,1,1) in('J','A','M')

8) Create a query that will display the employee name and commission amount. If the employee
does not earn commission, put “No Commission.” Label the column COMM.

Ans: select ename,nvl(to_char(comm),to_char('No Commission')) from emp


9) Create a query that displays the employees’ names and indicates the amounts of their salaries
through asterisks. Each asterisk signifies a hundred dollars. Sort the data in descending order
of salary. Label the column EMPLOYEE_AND_THEIR_SALARIES.
Ans:
select ename || ' ' ||
substr('*********************************************************************
*****', 1, sal / 100) as "EMPLOYEE_AND_THEIR_SALARIES" from emp order by sal
desc;

You might also like