1.字符串函数
mysql> select concat( 'a' , '-' , 'b' ) ;
+
| concat( 'a' , '-' , 'b' ) |
+
| a- b |
+
1 row in set ( 0.00 sec)
mysql> select c_name, c_madein, concat( c_name, c_madein) from commodity limit 5 ;
+
| c_name | c_madein | concat( c_name, c_madein) |
+
| 变形金刚- 擎天柱 | 中国 | 变形金刚- 擎天柱中国 |
| 变形金刚- 霸天虎 | 中国 | 变形金刚- 霸天虎中国 |
| 变形金刚- 威震天 | 美国 | 变形金刚- 威震天美国 |
| 魔仙玩偶1 | 中国 | 魔仙玩偶1 中国 |
| 超人玩偶 | 中国 | 超人玩偶中国 |
+
5 rows in set ( 0.00 sec)
mysql>
mysql> select upper( 'Jack' ) ;
+
| upper( 'Jack' ) |
+
| JACK |
+
1 row in set ( 0.00 sec)
mysql>
mysql> select lower( 'Jack' ) ;
+
| lower( 'Jack' ) |
+
| jack |
+
1 row in set ( 0.00 sec)
mysql>
mysql> select upper( 'Jack' ) ;
+
| upper( 'Jack' ) |
+
| JACK |
+
1 row in set ( 0.00 sec)
mysql>
mysql> select lower( 'Jack' ) ;
+
| lower( 'Jack' ) |
+
| jack |
+
1 row in set ( 0.00 sec)
mysql>
mysql> select left ( 'hello' , 2 ) ;
+
| left ( 'hello' , 2 ) |
+
| he |
+
1 row in set ( 0.00 sec)
mysql>
mysql> select right ( 'hello' , 2 ) ;
+
| right ( 'hello' , 2 ) |
+
| lo |
+
1 row in set ( 0.00 sec)
mysql>
mysql> select replace ( 'hello' , 'l' , 'k' ) ;
+
| replace ( 'hello' , 'l' , 'k' ) |
+
| hekko |
+
1 row in set ( 0.00 sec)
mysql>
mysql> select trim( ' hello ' ) ;
+
| trim( ' hello ' ) |
+
| hello |
+
1 row in set ( 0.00 sec)
mysql>
mysql> select length( trim( ' hello ' ) ) ;
+
| length( trim( ' hello ' ) ) |
+
| 5 |
+
1 row in set ( 0.00 sec)
mysql>
mysql> select substring( 'hello' , 1 , 3 ) ;
+
| substring( 'hello' , 1 , 3 ) |
+
| hel |
+
1 row in set ( 0.00 sec)
2.数值函数
mysql>
mysql> select abs( - 99 ) ;
+
| abs( - 99 ) |
+
| 99 |
+
1 row in set ( 0.00 sec)
mysql>
mysql> select ceil( 3.14 ) ;
+
| ceil( 3.14 ) |
+
| 4 |
+
1 row in set ( 0.00 sec)
mysql>
mysql> select floor( 3.14 ) ;
+
| floor( 3.14 ) |
+
| 3 |
+
1 row in set ( 0.00 sec)
mysql>
mysql> select mod ( 5 , 3 ) ;
+
| mod ( 5 , 3 ) |
+
| 2 |
+
1 row in set ( 0.00 sec)
mysql>
mysql> select rand( ) ;
+
| rand( ) |
+
| 0.29647299581810177 |
+
1 row in set ( 0.00 sec)
3.日期函数
mysql>
mysql> select now ( ) ;
+
| now ( ) |
+
| 2020 - 07 - 16 16 :00 :09 |
+
1 row in set ( 0.00 sec)
mysql>
mysql> select unix_timestamp( ) ;
+
| unix_timestamp( ) |
+
| 1594886443 |
+
1 row in set ( 0.00 sec)
mysql>
mysql> select year ( ) ;
ERROR 1064 ( 42000 ) : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1
mysql> select year ( now ( ) ) ;
+
| year ( now ( ) ) |
+
| 2020 |
+
1 row in set ( 0.00 sec)
4.流程函数
mysql>
mysql> select ifnull( c_outprice, 0 ) from commodity limit 10 ;
+
| ifnull( c_outprice, 0 ) |
+
| 50 |
| 45 |
| 245 |
| 12 |
| 99 |
| 99 |
| 3000 |
| 600 |
| 60 |
| 0 |
+
10 rows in set ( 0.00 sec)
mysql>
mysql> select case c_type when 1 then '玩具' when 2 then '文具' else '书籍' end case_when from commodity limit 10 ;
+
| case_when |
+
| 玩具 |
| 玩具 |
| 玩具 |
| 玩具 |
| 玩具 |
| 玩具 |
| 玩具 |
| 玩具 |
| 玩具 |
| 玩具 |
+
10 rows in set ( 0.00 sec)
5.其他系统函数
mysql>
mysql> select version( ) ;
+
| version( ) |
+
| 5.7 .30 - log |
+
1 row in set ( 0.00 sec)
mysql>
mysql> select user ( ) ;
+
| user ( ) |
+
| root@localhost |
+
1 row in set ( 0.00 sec)
mysql>
mysql> select database ( ) ;
+
| database ( ) |
+
| ishop |
+
1 row in set ( 0.00 sec)
mysql>
mysql> select md5( 'hello' ) ;
+
| md5( 'hello' ) |
+
| 5 d41402abc4b2a76b9719d911017c592 |
+
1 row in set ( 0.00 sec)