如何优化替换和查找功能? [英] How to optimize replace and find function?

查看:85
本文介绍了如何优化替换和查找功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建可以用sql中的超链接替换某些单词的函数。当我在sql中将该函数作为查询调用时,执行查询需要很长时间,超过2-3分钟。我假设这是因为, tag_libary 表有大约600,000条记录并且通过大量迭代会消耗大量的处理时间。

I am trying to create function which can replace certain words with hyperlink in sql. When I call the function as query in sql, its takes a really long time to execute the query, more than 2-3min. I assumed this is because, the tag_libary table has around 600,000 records and iterating through large number, would consume a lot of processing time.

CREATE FUNCTION dbo.ReplaceTags(@body VARCHAR(MAX))
RETURNS VARCHAR(MAX)
AS
BEGIN

SELECT @body = REPLACE(@body,name,'<a href="pagename.aspx?tag='+name+'">'+name+'</a>')
FROM Tag_Library

RETURN @body
END



因此,我正在写信寻求一些建议,如果有办法使这个sql函数最佳还是更好地将此函数更改为插入触发器?



如果可能请提供建议。


Hence, I am writing to seek some advice, if there is a way to make this sql function optimal or would it be better to change this function, into a insert trigger?

Please advice, if possible.

推荐答案

由于你有很多记录,所以可能需要时间。为什么不使用触发器而不是函数。它可以帮助你
Since you have a lot of records so it may take time. Why dont you use a trigger instead of a function. It may help you


这篇关于如何优化替换和查找功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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