sql server中replace()函數用法解析


知識點一:replace()的語法

REPLACE ( string_replace1 , string_replace2 , string_replace3 ) 參數解析: string_replace1 待搜索的字符串表達式。string_replace1 可以是字符數據或二 進制數據 string_replace2 待查找的字符串表達式。string_replace2 可以是字符數據或二 進制數據。 string_replace3 替換用的字符串表達式。string_replace3 可以是字符數據或二 進制數據。
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

知識點二: replace()的作用

用string_replace3替換string_replace1中出現的所有string_replace2。
  • 1

知識點三:replace()的返回值

如果參數是支持的字符數據類型之一,並且在string_replace1 中能夠找到 
string_replace2,那么返回替換后的字符串;反之, 返回 string_replace1;
如果參數是支持的 binary 數據類型之一,則返回二進制數據。
  • 1
  • 2
  • 3

知識點四:實例

1,字符串類型參數:

SELECT REPLACE('abcdefg bcd','bcd','xxx')
  • 1

結果為:axxxefg xxx

2,二進制類型參數:

SELECT REPLACE(100111001101,111,000)
  • 1

結果為:1000001101

用法

replace(str1,str2,str3)
說明:str3替換str1中出現的所有str2,返回新的字符串,如果有某個參數為NULL,此函數返回NULL
該函數可以多次替換,只要str1中還有str2存在,最后都被替換成str3
若str3為空,則刪除str2


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM