原因:在数据查询中replace函数无法对表table中text/ntext类型的字段colname进行了字符串操作。
解决方法:将text当作varchar(实际内容长度低于8000字节时)或把ntext当作nvarchar(实际内容长度低于4000字节时)。
但是当text字段内容长度超过8000或ntext字段内容长度超过4000字节时多出的字节会被截断而忽略掉。
这时我们可以使用max类型来解决这个问题。
原报错代码:
1
|
update
tablename
set
colname=
replace
(colname,
'oldtext'
,
'newtext'
);
|
修改后可执行代码:
1
|
update
tablename
set
colname=
replace
(
Cast
(colname
as
varchar
(8000)),
'oldtext'
,
'newtext'
);
|
1
|
update
tablename
set
colname=
replace
(
Cast
(colname
as
nvarchar(4000)),
'oldtext'
,
'newtext'
);
|