0% found this document useful (0 votes)
258 views

Exercise 3 Character and Number Function

This document contains examples of SQL functions that perform various operations on character and number data. It provides 6 exercises that demonstrate how to: 1) calculate and format salary increases, 2) concatenate employee names and jobs, 3) generate a composite identifier for employees, 4) search for employees by job name, 5) center department names, and 6) find and replace characters in employee names. The examples output formatted text, calculations, concatenations and other transformations of data using SQL functions.

Uploaded by

Faqihah Syazwani
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
258 views

Exercise 3 Character and Number Function

This document contains examples of SQL functions that perform various operations on character and number data. It provides 6 exercises that demonstrate how to: 1) calculate and format salary increases, 2) concatenate employee names and jobs, 3) generate a composite identifier for employees, 4) search for employees by job name, 5) center department names, and 6) find and replace characters in employee names. The examples output formatted text, calculations, concatenations and other transformations of data using SQL functions.

Uploaded by

Faqihah Syazwani
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Exercise 3: Functions - Character and Number

1. List the employee name and salary increased by 15% and expressed as a whole number of
dollars.

select ENAME, SAL, to_char(SAL*1.15,'$99,999.00') AS "SALARY IN DOLLAR"


from EMP;
2. Produce the following output.

EMPLOYEE_AND_JOB
----------------------------
SMITH CLERK
ALLEN SALESMAN
WARD SALESMAN
JONES MANAGER
MARTIN SALESMAN
BLAKE MANAGER
CLARK MANAGER
SCOTT ANALYST
KING PRESIDENT
TURNER SALESMAN
ADAMS CLERK
JAMES CLERK
FORD ANALYST
MILLER CLERK

14 records selected

SELECT ENAME || ' ' || JOB AS EMPLOYEE_AND_JOB


FROM emp;
3. Display a list of all employees with an identifier which is a composite of the first two characters
of their job, the middle two digits of their employee number and soundex code of their name.

NAME CODE
---------- ----------------
SMITH CL36S530
ALLEN SA49A450
WARD SA52W630
JONES MA56J520
MARTIN SA65M635
BLAKE MA69B420
CLARK AN78S300
KING PR83K520
TURNER SA84T656
ADAMS CL87A352
JAMES CL90J520
FORD AN90F630
MILlER CL93M460

select ENAME, SUBSTR(JOB,1,2)||SUBSTR(EMPNO,2,3)||SOUNDEX(ENAME) AS CODE


from EMP order by EMPNO ;

4. Do a case insensitive search for a list of employees with a job that the user enters. [Hint: use
UPPER].
5. Print a list of department names centred. Assume a column width of 20.

DEPARTMENT
------------------------------
ACCOUNTING
RESEARCH
SALES
OPERATIONS
6. Find the first occurance of the letter 'L' in employee names, and change the 'L' to an 'X'.

ENAME FIRST OCCURANCE_OF_L


------------------- ----------------------------------
SMITH SMITH
ALLEN AXLEN
WARD WARD
JONES JONES
MARTIN MARTIN
BLAKE BXAKE
CLARK CXARK
SCOTT SCOTT
KING KING
URNER TURNER
ADAMS ADAMS
JAMES JAMES
FORD FORD
MILLER MIXLER

You might also like