- mysql> select * from ss;
- +----+--------+
- | id | sid |
- +----+--------+
- | 1 | 001230 |
- | 4 | 010300 |
- | 2 | 012300 |
- | 3 | 123000 |
- +----+--------+
- 4 rows in set (0.09 sec)
- mysql> SELECT id,TRIM(LEADING '0' FROM sid) AS sid FROM ss;
- +----+--------+
- | id | sid |
- +----+--------+
- | 1 | 1230 |
- | 4 | 10300 |
- | 2 | 12300 |
- | 3 | 123000 |
- +----+--------+
- 4 rows in set (0.03 sec)
- mysql> SELECT id,TRIM(TRAILING '0' FROM sid) AS sid FROM ss;
- +----+-------+
- | id | sid |
- +----+-------+
- | 1 | 00123 |
- | 4 | 0103 |
- | 2 | 0123 |
- | 3 | 123 |
- +----+-------+
- 4 rows in set (0.03 sec)
- mysql> SELECT id,TRIM(BOTH '0' FROM sid) AS sid FROM ss;
- +----+------+
- | id | sid |
- +----+------+
- | 1 | 123 |
- | 4 | 103 |
- | 2 | 123 |
- | 3 | 123 |
- +----+------+
- 4 rows in set (0.02 sec)
本文转自hcymysql51CTO博客,原文链接:http://blog.51cto.com/hcymysql/1065631 ,如需转载请自行联系原作者