【发布时间】:2012-09-19 16:57:38
【问题描述】:
我正在尝试在 SQL 中使用 REPLACE 函数,但在尝试将字符串附加到列的当前内容的末尾时遇到问题。
set ActualRegex = REPLACE(ActualRegex, ActualRegex, ActualRegex + '[\d\D]*')
这些字符串将用于 C# 程序中的正则表达式检查,但这与问题并不特别相关。
当我尝试运行此查询时,我最终收到一条错误消息
Msg 8152, Level 16, State 14, Line 1
String or binary data would be truncated.
The statement has been terminated.
我检查了字段大小,结果字符串的长度不会超过字段的大小 (varchar(512))。除非发生了我不知道的奇怪事情,否则它们最多可能有 50 个字符。
提前感谢您的帮助!
编辑:这是完整的查询
update [Registration].[dbo].[MigrationOfTagTypes] set ActualRegex =
REPLACE(ActualRegex, ActualRegex, ActualRegex + '[\d\D]*')
where Regex != '' and Regex like '%\%' escape '\'
编辑:实际上,我想通了,结果发现我只是愚蠢而忽略了一些小事。显然,这些字段充满了附加到字符串末尾的大量空白,因此附加到这些字段会导致打破大小限制。 感谢所有帮助!
【问题讨论】:
-
这是 UPDATE 语句的一部分吗?
-
是的,整个语句是:update [Registration].[dbo].[MigrationOfTagTypes] set ActualRegex = REPLACE(ActualRegex, ActualRegex, ActualRegex + '[\d\D]*') where Regex != '' 和 Regex 之类的 '%\%' 转义 '\'
标签: sql regex string replace sql-server-2008-r2