目录

工欲善其事

实践出真知

活跃标签: linux java mysql 待分类 js springboot win10 电路 vue macOS nginx windows esp32 git docker idea maven esp8266 python Arduino

存档:

X

[ Mysql ] 中方法整理

字符串替换操作REPLACE

mysql中替换函数 REPLACE(s,s1,s2) 使用字符串 s2 替换字符串 s 中所有的字符串 s1。

【实例】使用 REPLACE 函数进行字符串替换操作,输入的 SQL 语句和执行过程如下所示。

mysql> SELECT REPLACE('aaa.mysql.com','a','w');
+----------------------------------+
| REPLACE('aaa.mysql.com','a','w') |
+----------------------------------+
| www.mysql.com                    |
+----------------------------------+
1 row in set (0.00 sec)

由运行结果可以看出,使用 REPLACE('aaa.mysql.com','a','w') 将“aaa.mysql.com”字符串的“a”字符替换为“w”字符,结果为“www.mysql.com”。

版本是否支持
5.7
8.0

将字符串转成小数再保留两位小数0填充

select CAST('' AS DECIMAL(10, 4));
# 0.0000
select CAST('1' AS DECIMAL(10, 4));
# 1.0000
select CAST('1.' AS DECIMAL(10, 4));
# 1.0000
select CAST('1.1' AS DECIMAL(10, 4));
# 1.1000

标题:[ Mysql ] 中方法整理
作者:llilei
地址:http://solo.llilei.work/articles/2022/04/28/1651106400218.html