MySQL生成指定长度字符串LPAD/RPAD

左侧填充使用LPAD

mysql> select lpad(123, 7, 0);
# 输出
+-----------------+
| lpad(123, 7, 0) |
+-----------------+
| 0000123         |
+-----------------+
1 row in set (0.21 sec)

右侧填充使用RPAD

mysql> select rpad(123, 6,'0');
# 输出
+------------------+
| rpad(123, 6,'0') |
+------------------+
| 123000           |
+------------------+
1 row in set (0.09 sec)

posted @ 2022-04-28 20:27  看不见的R  阅读(366)  评论(1)    收藏  举报