Sunteți pe pagina 1din 4

Course Code Type Course Code Here

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
 SQL> select lower(lastname||','||firstname) as "Complete Name", length(lastname) from employees
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
 SQL> select firstname||'earns'||salary||'monthly but wants'||salary*3 as "Dream Salaries" from employees;
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
 SQL> select lastname, lpad(salary,15,'$') as "salary" from employees 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******
 SQL> select lastname||lpad(salary,6,'*') as "employees and their salaries" from employees where
manager_id = 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’.
 SQL> select upper(firstname) as "pangalan" from employees 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.
 SQL> select firstname, length(firstname) as "number of character" from employees 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
 SQL> select firstname || 'salary is' || salary || 'if multiply by two then he/she got a new salary of' ||
salary*2 as "Increase" from employees 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.
 SQL> select lpad(salary,15,'$'), rpad(salary,10,'@') from employees where employee_id in
('201','176','144');
9. Write a query using SUBSTR function that returns the job_id = ‘REP’.
Sample output:
Job_id
SA_REP
 SQL> select job_id from employees where substr(job_id,4)='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.
 SQL> select lastname, instr(lastname,'a') from employees 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

 SQL> select round(563.396,2), round(563.396,1), round(563.396,-2), round(563.396,-1) from dual;

 ROUND(563.396,2) ROUND(563.396,1) ROUND(563.396,-2) ROUND(563.396,-1)


---------------- ---------------- ----------------- -----------------
563.4 563.4 600 560
12. Compute for the remainder of 100 to 10 and 9 to 2 using the dual table.
 SQL> select mod(100,10), mod(9,2) from dual;
13. Write a query that display the truncated value of the following number.
563.396,2
563.396,1
563.396,-2
563.396,-1
 SQL> select trunc(563.396,2), trunc(563.396,1), trunc(563.396,-2), trunc(563.396,-1) from dual;

 TRUNC(563.396,2) TRUNC(563.396,1) TRUNC(563.396,-2) TRUNC(563.396,-1)


---------------- ---------------- ----------------- -----------------
563.39 563.3 500 560
14. Write a query that will trim the letter ‘A’ from lastname of all employees whose department_id between
60 and 90.
 SQL> select lastname, trim('a' from lastname) from employees where department_id between 60 and
90;
15. What is DUAL Table?
 Dual Table is owned by the user SYS and can be accessed by all users.

S-ar putea să vă placă și