MySQL provides built-in functions that perform special operations.
Aggregate functions operate on a set of data. These are usually used to perform some action on a complete set of returned rows. For example, SELECT AVG(height) FROM kids would return the average of all the values of the height field in the kids table.
General functions operate on one or more discrete values. We have omitted a few rarely used functions with very specialized applications.
mysql> SELECT DECODE(ENCODE('open sesame', 'please'), 'please'); +---------------------------------------------------+ | DECODE(ENCODE('open sesame', 'please'), 'please') | +---------------------------------------------------+ | open sesame | +---------------------------------------------------+ 1 row in set (0.01 sec)
mysql> SELECT EXPORT_SET(5, "y", "n", "", 8); +--------------------------------+ | EXPORT_SET(5, "y", "n", "", 8) | +--------------------------------+ | ynynnnnn | +--------------------------------+ 1 row in set (0.00 sec) mysql> SELECT EXPORT_SET(5, "y", "n", ",", 8); +---------------------------------+ | EXPORT_SET(5, "y", "n", ",", 8) | +---------------------------------+ | y,n,y,n,n,n,n,n | +---------------------------------+ 1 row in set (0.00 sec)
mysql> SELECT MAKE_SET(5, "a", "b", "c", "d", "e", "f"); +-------------------------------------------+ | MAKE_SET(5, "a", "b", "c", "d", "e", "f") | +-------------------------------------------+ | a,c | +-------------------------------------------+ 1 row in set (0.01 sec)
Copyright © 2003 O'Reilly & Associates. All rights reserved.