Week010 SingleRow LabExer006 ZENZ
Week010 SingleRow LabExer006 ZENZ
Week010 SingleRow LabExer006 ZENZ
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
LOWER(LASTNAME)||","||LOWER(FIRSTNAME) "Complete Name", LENGTH(LASTNAME)
"LENGTH(LASTNAME)" FROM EMP 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
SELECT CONCAT(FIRSTNAME,’earns’,1FNULL(SALARY,0),’monthly but wants’, /*Concatenate
FirstName with earns and Salary with String monthly but wants with dream
salary”IFNULL(SALARY,0)*3) AS DREAM_SALARIES /*Dream Salary is 3 times of
salary*/FROMEMPLOYEES;
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
SELECT LASTNAME, LPAD(FLOOR(IFNULL(SALARY,0)), 15, ‘$’)AS SALARY /*Salary to be
15character long*/FROM EMPLOYEES /*Table Name*/WHERE department_id = 60 OR job_id LIKE
‘_T%’; /* Filter for dept id : and 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******
SELECT CONCAT (LASTNAME, LPAD(FLOOR(IFNULL(SALARY,0)), 6,’*’)) AS ‘Employees and
theirSalaries’/ *Format salary to 6 character long*/FROM EMPLOYEESWHERE SALARY
BETWEEN 4000 AND 6000; /*Salary between 4k & 6k*/
5. Write a query that display the firstname in capitalized format rename the column as pangalan whose
job_id is equal to ‘SA_REP’.
SELECT UPPER (FIRSTNAME) AS pangalan /*Upper converts string to upper case*/FROM
EMPLOYEESWHERE 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.
SELECT FIRSTNAME, CHAR_LENGTH(FIRSTNAME) AS ' Number of Character of all
employees'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
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.
9. Write a query using SUBSTR function that returns the job_id = ‘REP’.
Sample output:
Job_id
SA_REP
SELECT JOB_ID FROM EMPLOYEESWHERE 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.
SELECT LASTNAME term EMPLOYEES where LASTNAME like ‘A%’ and 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) FROM DUAL;
ROUND(563.396,2)
----------------
563.4
SQL> SELECT ROUND(563.396,1) FROM DUAL;
ROUND(563.396,1)
----------------
563.4
SQL> SELECT ROUND(563.396,-2) FROM DUAL;
ROUND(563.396,-2)
-----------------
600SQL> SELECT ROUND(563.396,-1) FROM DUAL;
ROUND(563.396,-1)
-----------------
560
12. Compute for the remainder of 100 to 10 and 9 to 2 using the dual table.
SELECT REMAINDER (100,10) FROM DUAL;O/P:- 0
SELECT REMAINDER (9,2) FROM DUAL; O/P:- -1
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
SELECT TRUNCATE (563.396,2) FROM DUAL; O/P:- 563.3
SELECT TRUNCATE (563.396,1) FROM DUAL; O/P:- 563.3
SELECT TRUNCATE (563.396,1) FROM DUAL; O/P;-500
SELECT TRUNCATE (563.396,-1) FROMDUAL; O/P- 560
14. Write a query that will trim the letter ‘A’ from lastname of all employees whose department_id between
60 and 90.
SELECT TRIM(LEADING ‘A’ FROM LASTNAME)
FROM EMPLOYEES where department_id between 60 and 90;
15. What is DUAL Table?
Dual table is present by default in oracle and other database which is special one-row and one-column
table.It is suitable for selecting SYSDATE,USER etc.