Miscellaneous Character Functions

The following sections show a few other character functions worth mentioning. Once again, these are functions that are fairly common among major implementations.

Finding a Value's Length

The LENGTH function is a common function used to find the length of a string, number, date, or expression in bytes. The syntax is

LENGTH(CHARACTER STRING)
ExampleMeaning
SELECT LENGTH
FROM EMPLOYEE_TBL;
This SQL statement (LAST_NAME) returns the length of the last name for each employee.
							SELECT PROD_DESC, LENGTH(PROD_DESC)
							FROM PRODUCTS_TBL;
						
 PROD_DESC LENGTH(PROD_DESC) ------------------------ ----------------- WITCHES COSTUME 15 PLASTIC PUMPKIN 18 INCH 23 FALSE PARAFFIN TEETH 19 LIGHTED LANTERNS 16 ASSORTED COSTUMES ...

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.