Appendix D. MySQL Functions
Having functions built into MySQL substantially reduces the speed of performing complex queries, as well as their complexity. If you wish to learn more about the available functions, you can visit the following URLs:
-
String functions: tinyurl.com/phpstringfuncs
-
Date and time: tinyurl.com/phpdateandtime
But, for easy reference, here are some of the most commonly used MySQL functions.
String Functions
CONCAT(str1,str2, ...)-
Returns the result of concatenating
str1,str2, and any other parameters (orNULLif any argument isNULL). If any of the arguments are binary, then the result is a binary string; otherwise, the result is a nonbinary string. The code returns the string"MySQL":SELECT CONCAT('My', 'S', 'QL'); CONCAT_WS(separator,str1,str2, ...)-
This works in the same way as
CONCATexcept it inserts a separator between the items being concatenated. If the separator isNULL, the result will beNULL, butNULLvalues can be used as other arguments, which will then be skipped. This code returns the string"Truman,Harry,S":SELECT CONCAT_WS(',', 'Truman', 'Harry', 'S'); LEFT(str,len)-
Returns the leftmost
lencharacters from the stringstr(orNULLif any argument isNULL). The following code returns the string"Chris":SELECT LEFT('Christopher Columbus', '5'); RIGHT(str,len)-
Returns the rightmost
lencharacters from the stringstr(orNULLif any argument isNULL). This code returns the string"Columbus":SELECT RIGHT('Christopher ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access