【发布时间】:2021-10-23 18:14:33
【问题描述】:
我想在 MS SQL 中清理字符串并用下划线_替换各种字符。
以下代码可以实现:
DECLARE @string nvarchar(MAX)
DECLARE @new_string nvarchar(MAX)
SET @string = 'This is.my string/That Needs=cleaning'
SET @new_string = REPLACE(REPLACE(REPLACE(REPLACE(@string, ' ', '_'), '.', '_'), '/', '_'), '=', '_')
SELECT @new_string
这将返回“This_is_my_string_That_Needs_cleaning”
我将使用它来清理文件名。
有没有更有效的方法,也许是通过正则表达式?
【问题讨论】:
标签: sql sql-server replace