[转]SQL中replace()函数的用法
(2018-08-29 10:19:21)
标签:
sqlreplace |
分类: 计算机 |
原文链接:
https://blog.csdn.net/xiaokangmiclong/article/details/49868707
http://www.cnblogs.com/1906859953Lucas/p/9244495.html
replace()函数表示将用一个字符串替换字符串中的所出现的特定内容。语法为:replace(字段1,字段2,字段3),意思为字段3将会替换字段1里与字段2相同的内容
列如:
table1
state
20
select replace(state,'2','1') from table1
结果如下:
state
10
REPLACE (
string_replace1 , string_replace2 , string_replace3 ) 参数解析: string_replace1 待搜索的字符串表达式。string_replace1
可以是字符数据或二 进制数据 string_replace2 待查找的字符串表达式。string_replace2
可以是字符数据或二 进制数据。 string_replace3 替换用的字符串表达式。string_replace3
可以是字符数据或二 进制数据。 |
实例
字符串类型参数:
1
|
SELECT REPLACE ( 'abcdefg bcd' , 'bcd' , 'xxx' ) |
结果为:axxxefg xxx
二进制类型参数:
1
2
|
SELECT REPLACE (100111001101,111,000) SELECT REPLACE (100111001101,111,0) |
结果为:100101
结果为:100101
1
2
3
|
如果参数是支持的字符数据类型之一,并且在string_replace1 中能够找到 string_replace2,那么返回替换后的字符串;反之, 返回 string_replace1; 如果参数是支持的 binary 数据类型之一,则返回二进制数据。 |
这个函数有一点不足是不支持 text,ntext类型字段的替换