The Concept of Combining Character Functions

Most functions can be combined in a single SQL statement. SQL would be far too limited if function combinations were not allowed. The following examples show how some functions can be combined with one another in a query:

						SELECT LAST_NAME || ', ' || FIRST_NAME NAME,
						SUBSTR(EMP_ID,1,3) || '-' ||
						SUBSTR(EMP_ID,4,2) || '-' ||
						SUBSTR(EMP_ID,6,4) ID
						FROM EMPLOYEE_TBL;
					
NAME               ID
------------------ -----------
STEPHENS, TINA     311-54-9902
PLEW, LINDA        442-34-6889
GLASS, BRANDON     213-76-4555
GLASS, JACOB       313-78-2439
WALLACE, MARIAH    220-98-4332
SPURGEON, TIFFANY  443-67-9012

6 rows selected.

The following example combines two functions in the query (concatenation with substring). By pulling the EMP_ID column ...

Get Sams Teach Yourself SQL in 24 Hours, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.