mysql> SELECT CONCAT('mysql','5.6'); +-----------------------+ | CONCAT('mysql','5.6') | +-----------------------+ | mysql5.6 | +-----------------------+ 1 row in set (0.09 sec) mysql> SELECT CONCAT('mysql','-','5.6'); +---------------------------+ | CONCAT('mysql','-','5.6') | +---------------------------+ | mysql-5.6 | +---------------------------+ 1 row in set (0.00 sec)
mysql> SELECT * FROM tdb_test; +----+------------+-----------+ | id | first_name | last_name | +----+------------+-----------+ | 1 | A | B | | 2 | Jack | Bob | | 3 | tom% | 123 | +----+------------+-----------+ 3 rows in set (0.00 sec) mysql> SELECT CONCAT(first_name,last_name) AS fullname FROM tdb_test; +----------+ | fullname | +----------+ | AB | | JackBob | | tom%123 | +----------+ 3 rows in set (0.00 sec)
mysql> SELECT CONCAT_WS('|','A','B','C'); +----------------------------+ | CONCAT_WS('|','A','B','C') | +----------------------------+ | A|B|C | +----------------------------+ 1 row in set (0.00 sec) mysql> SELECT CONCAT_WS('-','mysql','5.6'); +------------------------------+ | CONCAT_WS('-','mysql','5.6') | +------------------------------+ | mysql-5.6 | +------------------------------+ 1 row in set (0.00 sec)
mysql> SELECT FORMAT(12560.75,1); +--------------------+ | FORMAT(12560.75,1) | +--------------------+ | 12,560.8 | +--------------------+ 1 row in set (0.01 sec) LOWER()和 UPPER() mysql> SELECT LOWER('MySql'); +----------------+ | LOWER('MySql') | +----------------+ | mysql | +----------------+ 1 row in set (0.00 sec) mysql> SELECT UPPER('MySql'); +----------------+ | UPPER('MySql') | +----------------+ | MYSQL | +----------------+ 1 row in set (0.00 sec)
mysql> SELECT LEFT('MySQL',2); +-----------------+ | LEFT('MySQL',2) | +-----------------+ | My | +-----------------+ 1 row in set (0.00 sec)
mysql> SELECT RIGHT('MySQL',2); +------------------+ | RIGHT('MySQL',2) | +------------------+ | QL | +------------------+ 1 row in set (0.00 sec)
mysql> SELECT LENGTH('MySQL'); +-----------------+ | LENGTH('MySQL') | +-----------------+ | 5 | +-----------------+ 1 row in set (0.02 sec)
mysql> SELECT TRIM(LEADING '?' FROM '??MySQL???'); +-------------------------------------+ | TRIM(LEADING '?' FROM '??MySQL???') | +-------------------------------------+ | MySQL??? | +-------------------------------------+ 1 row in set (0.02 sec) mysql> SELECT TRIM(TRAILING '?' FROM '??MySQL???'); +--------------------------------------+ | TRIM(TRAILING '?' FROM '??MySQL???') | +--------------------------------------+ | ??MySQL | +--------------------------------------+ 1 row in set (0.00 sec) mysql> SELECT TRIM(BOTH '?' FROM '??MySQL???'); +----------------------------------+ | TRIM(BOTH '?' FROM '??MySQL???') | +----------------------------------+ | MySQL | +----------------------------------+ 1 row in set (0.01 sec)
mysql> SELECT REPLACE('??My??SQL???','?',''); +--------------------------------+ | REPLACE('??My??SQL???','?','') | +--------------------------------+ | MySQL | +--------------------------------+ 1 row in set (0.00 sec)
mysql> SELECT SUBSTRING('MySQL',1,2); +------------------------+ | SUBSTRING('MySQL',1,2) | +------------------------+ | My | +------------------------+ 1 row in set (0.00 sec)
mysql> SELECT SUBSTRING('MySQL',3); +----------------------+ | SUBSTRING('MySQL',3) | +----------------------+ | SQL | +----------------------+ 1 row in set (0.00 sec)
mysql> SELECT SUBSTRING('MySQL',-1); +-----------------------+ | SUBSTRING('MySQL',-1) | +-----------------------+ | L | +-----------------------+ 1 row in set (0.04 sec)
mysql> SELECT 'MySQL' LIKE 'M%'; +-------------------+ | 'MySQL' LIKE 'M%' | +-------------------+ | 1 | +-------------------+ 1 row in set (0.00 sec)
mysql> SELECT * FROM tdb_test; +----+------------+-----------+ | id | first_name | last_name | +----+------------+-----------+ | 1 | A | B | | 2 | Jack | Bob | | 3 | tom% | 123 | +----+------------+-----------+ 3 rows in set (0.00 sec)
mysql> SELECT * FROM tdb_test WHERE first_name LIKE '%o%'; +----+------------+-----------+ | id | first_name | last_name | +----+------------+-----------+ | 3 | tom% | 123 | +----+------------+-----------+ 1 row in set (0.00 sec)
mysql> SELECT * FROM tdb_test WHERE first_name LIKE '%%%'; +----+------------+-----------+ | id | first_name | last_name | +----+------------+-----------+ | 1 | A | B | | 2 | Jack | Bob | | 3 | tom% | 123 | +----+------------+-----------+ 3 rows in set (0.00 sec)
mysql> SELECT * FROM tdb_test WHERE first_name LIKE '%1%%' ESCAPE '1'; +----+------------+-----------+ | id | first_name | last_name | +----+------------+-----------+ | 3 | tom% | 123 | +----+------------+-----------+ 1 row in set (0.00 sec)