Supplemental Examples of MySQL Character Functions

This section lists the syntax and examples of MySQL character functions. These functions will be used in the Workshop. Note similarities and differences to ANSI syntax as previously shown in this chapter. MySQL character functions are listed in addition to ANSI SQL functions because character functions tend to vary widely between SQL implementations.

LENGTH

LENGTH(str) returns the length of the string str.

mysql> select LENGTH('text');
        -> 4
mysql> select OCTET_LENGTH('text');
        -> 4

Note that for CHAR_LENGTH(), multibyte characters are only counted once.

LOCATE

LOCATE(substr,str) returns the position of the first occurrence of substring substr in string str. It returns 0 if substr is not in ...

Get Sams Teach Yourself SQL in 21 Days, Fourth 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.