t-sql 替换文本字段 [英] t-sql replace on text field

查看:26
本文介绍了t-sql 替换文本字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个经典问题,需要对 sql 2000 数据库中的文本字段进行字符串替换.这可以是对整个列的更新,也可以是我不挑剔的单个字段.

I have hit a classic problem of needing to do a string replace on a text field in an sql 2000 database. This could either be an update over a whole column or a single field I'm not fussy.

我找到了一些关于如何使用 updatetext 来实现它的示例,但它们往往在存储过程中,有没有人知道包装在函数中的类似东西,以便我可以像通常使用 Replace 一样使用它().对于不知道的人来说,Replace() 函数的问题在于它不支持文本字段.

I have found a few examples of how to use updatetext to achieve it but they tend to be in stored procedures, does anyone know of a similar thing that is wrapped into a function so I can use it like I would usually use Replace(). The problem with the Replace() function for anyone who isn't aware is that it doesn't support text fields.

我意识到我可能可以摆脱 varchar(8000),因此已将字段交换为解决问题的这种类型.我从来没有找到真正的解决方案.

I realised I could probably get away with varchar(8000) so have swapped the fields to this type which fixes the issue. I never found a true solution.

推荐答案

恐怕你不能在函数内做到这一点

I am afraid you cannot do it within a function

当您尝试声明如下函数时:

When you try to declare a function like:

create function dbo.textReplace(
@inText as text)
returns text
as 
begin
    return 'a' -- just dummy code
end

您将收到以下错误:

The text data type is invalid for return values.

换句话说,你不能为文本数据类型编写一个简单的 REPLACE 函数

In other words you could not write a simple equivalent of REPLACE function for the text data type

这篇关于t-sql 替换文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆