mysql字符串格式化方式
作者:寻梦太极 时间:2024-01-16 14:13:31
mysql字符串格式化
今天有一个需求,mysql查询返回的格式为:80% ,而数据库中存储的是0.89的格式
sql写法如下:
select CONCAT(exampaper_avg_accuracy*100,"%") ?from class_everyday_statistic_result
结果如下:
mysql格式化字符串长度不够补0
1.前面补零
LPAD(str,len,padstr) 返回字符串 str, 其左边由字符串padstr 填补到len 字符长度。假如str 的长度大于len, 则返回值被缩短至 len 字符。
select LPAD('1', 8, 0)
结果
select LPAD('12', 1, 0)
结果
2.后面补0
RPAD(str,len,padstr) 返回字符串 str, 其右边由字符串padstr 填补到len 字符长度。假如str 的长度大于len, 则返回值被缩短至 len 字符。
select RPAD('1', 8, 0)
结果
select RPAD('12', 1, 0)
结果
来源:https://blog.csdn.net/xzj80927/article/details/90643530
标签:mysql,字符串,格式化
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
js 原型对象和原型链理解
2024-04-23 09:20:23
![](https://img.aspxhome.com/file/2023/2/135592_0s.jpg)
五个提升Python的执行效率的技巧分享
2021-01-07 09:52:45
关于文件命名
2009-09-18 16:29:00
Python OpenCV实现图形检测示例详解
2023-05-23 15:36:39
![](https://img.aspxhome.com/file/2023/8/103498_0s.jpg)
Vue项目如何设置反向代理和cookie设置问题
2023-07-02 16:39:03
PHP getName()函数讲解
2023-06-06 08:28:25
![](https://img.aspxhome.com/file/2023/6/55406_0s.png)
14道基础Python练习题(附答案)
2023-07-23 02:27:41
![](https://img.aspxhome.com/file/2023/8/110238_0s.png)
FrontPage创建HTML/ASP混合页面
2008-05-08 14:26:00
Python多线程、异步+多进程爬虫实现代码
2023-07-29 03:28:42
Python开发入门——迭代的基本使用
2022-12-11 23:16:05
python使用tkinter实现屏幕中间倒计时
2021-03-10 22:28:11
![](https://img.aspxhome.com/file/2023/5/133745_0s.jpg)
获得当前数据库对象依赖关系的实用算法
2009-01-08 13:28:00
python3.3使用tkinter开发猜数字游戏示例
2023-09-05 06:53:02
解决PHP mysql_query执行超时(Fatal error: Maximum execution time …)
2023-11-17 08:13:30
用Python画小女孩放风筝的示例
2021-11-20 09:40:25
![](https://img.aspxhome.com/file/2023/2/128572_0s.jpg)
JSP EL表达式详细介绍
2023-07-02 22:32:32
![](https://img.aspxhome.com/file/2023/9/97899_0s.jpg)
解决使用Pandas 读取超过65536行的Excel文件问题
2022-03-28 09:17:29
![](https://img.aspxhome.com/file/2023/8/124198_0s.jpg)
在windows下 1045 access denied for user
2010-03-04 11:44:00
2008年情人节各网站节日Logo欣赏
2008-02-17 14:12:00
![](https://img.aspxhome.com/file/UploadPic/20082/17/2008217141834880s.gif)
python使用matplotlib库生成随机漫步图
2021-03-01 15:11:37
![](https://img.aspxhome.com/file/2023/1/97261_0s.jpg)