0% found this document useful (0 votes)
73 views8 pages

LabExer006 Beronio AbrahamJr

This document provides instructions and examples for a series of SQL queries and PL/SQL exercises involving the Employees table. The exercises demonstrate various SQL functions like concatenation, formatting, conditional logic, aggregation, and more. Sample outputs are included to check the results of each query. The goal is to practice different SQL and PL/SQL techniques using the Employees data.

Uploaded by

Mary Jane Pagay
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)
73 views8 pages

LabExer006 Beronio AbrahamJr

This document provides instructions and examples for a series of SQL queries and PL/SQL exercises involving the Employees table. The exercises demonstrate various SQL functions like concatenation, formatting, conditional logic, aggregation, and more. Sample outputs are included to check the results of each query. The goal is to practice different SQL and PL/SQL techniques using the Employees data.

Uploaded by

Mary Jane Pagay
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/ 8

Course Code CS351

Database Management System


Description
1
College / Department:
LabExer No. 006
Online Education
Laboratory Exercise Page 1 of 1

Direction:
 Use the Employees table (copy and paste the code in SQL
command line)
 Write the PL/SQL based on the requirement in each number.
 Note: Sample output is just a guide, it does not necessarily that the value to your output should be equal
to the sample output.

1. Write a query that display the employees lastname concatenated with firstname and put a ‘, (comma)’ in
between. Rename the column as Complete Name. Note all values in Complete Name column should be
in lowercase plus display the length of employees lastname for all employees whose lastname starts with
letter M sort the lastname in its default order.
Sample output:
Complete Name LENGTH(LASTNAME)
mourgos, anna 7

ANSWER:
SQL> select lower(LASTNAME||' , '||FIRSTNAME) as "Complete Name",
2 length(LASTNAME)
3 from EMPLOYEES
4 where LASTNAME like 'M%';
2. Write a query that display the Firstname concatenated to employees original salary plus concatenate
again a new column salary that multiplies the original salary into three. Rename the column as Dream
Salaries.Note sort the salary in descending order.
Sample output:
Dream Salaries
King earns 24000 monthly but wants 72000
ANSWER:
SQL> select FIRSTNAME||' earns '||SALARY||' monthly but wants '||Salary*3
2 as "DREAM SALARIES"
3 from EMPLOYEES
4 ORDER BY SALARY DESC;

3. Write a query that


display the lastname and
salary of all employees
whose department_id =
60 or job_id like ‘_T%’.
Format the salary to be
15 character long, left
padded with ‘$’ as
special
character. Label the
column Salary.
Sample output:
Lastname salary
King $$$$$$$$$240000
ANSWER:
SQL> select LASTNAME,lpad(SALARY,15,'$')SALARY
2 from EMPLOYEES
3 where DEPARTMENT_ID=60 or JOB_ID LIKE '_T%';

4. Write a query that display the employees lastname concatenated to salary. Format the salary column to 6
character long left padded with ‘*’ as special character for all employees whose manager_id is null or
salary between 4000 and 6000 Rename the column as employees and their Salaries.
Sample output:
Employees and their Salaries
King******
ANSWER:
SQL> select LASTNAME||''||lpad(SALARY,6,'*')
2 as "Employess and their Salaries"
3 from EMPLOYEES
4 WHERE MANAGER_ID IS NULL OR SALARY BETWEEN 4000 AND 6000;
5. Write a query that display the firstname in capitalized format rename the column as pangalan whose
job_id is equal to ‘SA_REP’.

ANSWER:
SQL> select UPPER(FIRSTNAME) AS PANGALAN
2 from EMPLOYEES
3 WHERE JOB_ID='SA_REP';

6. Write a query that display the firstname and length of firstname rename the column length of firstname
as Number of Character of all employees whose salary is between 4400 and 8300.
ANSWER:
SQL> select FIRSTNAME,LENGTH(FIRSTNAME) AS "NUMBER OF CHARACTER"
2 from EMPLOYEES
3 WHERE SALARY BETWEEN 4400 AND 8300;
7. Write a query that display the firstname concatenated to salary with additional column salary that
provides a computation of salary * 2. Rename the column as Increase of all employees whose lastname
ends with N.
Sample output:
Increase
Jennifer salary is 4400 if multiply by two then he/she got a new salary of 8800
ANSWER:
SQL> select FIRSTNAME||' salary is '||SALARY||' if multiply by two the he/she got new salary of '||SALARY*2
2 AS "Increase"
3 from EMPLOYEES
4 WHERE LASTNAME LIKE '%N';

8. Write a query that displays the salary leftpadded with 15 character long and ‘$’ as special character and
another column salary right padded with 10 character long with ‘@’ as special character used of all
employees in 201, 176 and 144.
ANSWER:
SQL> select SALARY,lpad(SALARY,15,'$'),rpad(SALARY,10,'@')
2 from EMPLOYEES
3 WHERE EMPLOYEE_ID=201 OR EMPLOYEE_ID=176 OR EMPLOYEE_ID=144;
9. Write a query using SUBSTR function that returns the job_id = ‘REP’.
Sample output:
Job_id
SA_REP
ANSWER:
SQL> select SUBSTR("JOB_ID",1,6)JOB_ID
2 from EMPLOYEES
3 WHERE JOB_ID LIKE '%REP';

10. Write a query that display the lastname plus new column lastname that shows the character position of
‘A’ from the column lastname of all employees whose salary >=11000.
ANSWER:
SQL> select LASTNAME, INSTR(LASTNAME,'A')
2 from EMPLOYEES
3 WHERE SALARY >=11000;

11. Write a query that display the rounded value of the following number using the DUAL table.
563.396,2
563.396,1
563.396,-2
563.396,-1
ANSWER:
SQL> select ROUND(563.396,2), ROUND(563.396,1), ROUND(563.96,-2), ROUND(563.96,-1)
2 from DUAL;

12. Compute for the remainder of 100 to 10 and 9 to 2 using the dual table.
ANSWER:
SQL> select MOD(100,10),MOD(9,2)
2 from DUAL;

13. Write a query that display the truncated value of the following number.

563.396,1
563.396,-2
563.396,-1
ANSWER: SQL> select TRUNC(563.396,2), TRUNC(563.396,1), TRUNC(563.396,-2),TRUNC(563.396,-1)
2 from DUAL;

14. Write a query that will trim the letter ‘A’ from lastname of all employees whose department_id between
60 and 90.
ANSWER:
SQL> SELECT LASTNAME, TRIM('A' FROM LASTNAME)
2 FROM EMPLOYEES
3 WHERE DEPARTMENT_ID BETWEEN 60 AND 90;
15. What is DUAL Table?
ANSWER:
- A special one-row, one column table present by default in Oracle and other database
installations.
- Owned by the user SYS and can be accessed by all users.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy