mysql substring()函数,字符串分割

 

mysql> select * from test;
+----+------------+-------+-----------+
| id | name       | score | subject   |
+----+------------+-------+-----------+
|  1 | xiaoming   |    89 | shuxue    |
|  2 | xiaohong   |    89 | shuxue    |
|  3 | xiaohong   |    80 | english   |
|  4 | xiaohong   |    80 | physics   |
|  5 | xiaohong   |    80 | astronaut |
|  6 | xiaoming   |    80 | physics   |
|  7 | xiaoming   |    80 | astronaut |
|  8 | xiaoming   |    80 | english   |
|  9 | xiaobai    |    80 | astronaut |
| 10 | 1.2xiaobai |    80 | english   |
| 11 | 2.2xiaobai |    80 | physics   |
| 12 | 3xiaobai   |    80 | shuxue    |
| 13 | 123xiaohei |    80 | astronaut |
| 14 | xiaohei    |    80 | shuxue    |
| 15 | xiaohei    |    80 | physics   |
| 16 | .12xiaohei |    80 | english   |
+----+------------+-------+-----------+
16 rows in set (0.00 sec)


mysql> select substring(name,4,7) from test where id=3;
+---------------------+
| substring(name,4,7) |
+---------------------+
| ohong               |
+---------------------+
1 row in set (0.00 sec)


mysql> select substring(name,4,1) from test where id=3;
+---------------------+
| substring(name,4,1) |
+---------------------+
| o                   |
+---------------------+
1 row in set (0.00 sec)


mysql> select substring(name,4,2) from test where id=3;
+---------------------+
| substring(name,4,2) |
+---------------------+
| oh                  |
+---------------------+
1 row in set (0.00 sec)



mysql> select substring(name,1,2) from test where id=3;
+---------------------+
| substring(name,1,2) |
+---------------------+
| xi                  |
+---------------------+
1 row in set (0.00 sec)



mysql> select substring(name,0,5) from test where id=3;
+---------------------+
| substring(name,0,5) |
+---------------------+
|                     |
+---------------------+
1 row in set (0.00 sec)

 

 

 

posted @ 2019-08-06 11:12  anobscureretreat  阅读(596)  评论(0编辑  收藏  举报