Giả định nghĩa sau đây:Làm thế nào để trả về một nvarchar (max) trong một UDF CLR?
/// <summary>
/// Replaces each occurrence of sPattern in sInput with sReplace. This is done
/// with the CLR:
/// new RegEx(sPattern, RegexOptions.Multiline).Replace(sInput, sReplace).
/// The result of the replacement is the return value.
/// </summary>
[SqlFunction(IsDeterministic = true)]
public static SqlString FRegexReplace(string sInput, string sPattern,
string sReplace)
{
return new Regex(sPattern, RegexOptions.Multiline).Replace(sInput, sReplace);
}
Đi qua trong một giá trị nvarchar(max)
cho sInput
với chiều dài> 4000 sẽ dẫn đến việc giá trị được cắt ngắn (tức là kết quả của việc gọi UDF này là nvarchar(4000)
như trái ngược với nvarchar(max)
bạn là một ngôi sao, thưa bạn :) –
Cơ chế đó được mô tả rõ ràng trong tham chiếu tôi đã trích dẫn - câu trả lời bạn đã bỏ phiếu. – bielawski