我们有一个使用 UDF 的存储过程。我们需要动态修改这些 UDF 的内容。是的,我知道,我知道……不是我的选择。这正是我们要做的:
- 读取 UDF 的内容
- 修改内容并创建新的UDF
- 在
executesql
语句中使用 UDF
有没有办法将 udf 的内容转换为 varchar(或 nvarchar),然后我可以使用字符串函数进行修改?
最佳答案
select object_definition(object_id('UDFName'))
Is there a way to get the contents of a udf into a varchar (or nvarchar) that I can then modify using string functions?
declare @str nvarchar(max)
-- get function definition to @str
select @str = object_definition(object_id('UDFName'))
-- Modify definition
set @str = replace(@str, 'CREATE FUNCTION', 'ALTER FUNCTION')
-- execute alter function
exec (@str)
关于sql-server - 将 UDF 的语句加载到字符串变量中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5734115/