[英]Getting “Cannot find the type nvarchar(MAX)” when adding new CLR user defined function
I have created a new function in an assembly which has been successfully added as a CLR Assembly to my SQL server.我在程序集中创建了一个新函数,该函数已作为 CLR 程序集成功添加到我的 SQL 服务器。 Now I am trying to create a SQL user defined function to map to the new method in that assembly.现在我正在尝试创建一个 SQL 用户定义函数来映射到该程序集中的新方法。 I have other methods in the assembly which have been mapped successfully.我在程序集中有其他方法已成功映射。
Here is my function这是我的功能
CREATE FUNCTION [dbo].[FromCamelCase](@value [nvarchar(MAX)])
RETURNS [nvarchar(MAX)] WITH EXECUTE AS CALLER
AS
EXTERNAL NAME [Tools_CLR].[UserDefinedFunctions].[FromCamelCase]
GO
On execute, I am getting this error.执行时,我收到此错误。
Msg 15151, Level 16, State 1, Procedure FromCamelCase, Line 2
Cannot find the type 'nvarchar(MAX)', because it does not exist or you do not
have permission.
I have tried changing the type from nvarchar
to just varchar
.我尝试将类型从nvarchar
更改为varchar
。 I have also tried changing the size from MAX
to 4000 and also just 50.我还尝试将大小从MAX
更改为 4000,也仅更改为 50。
Here is my C# method, for reference.这是我的 C# 方法,供参考。
[Microsoft.SqlServer.Server.SqlFunction]
public static string FromCamelCase(string val)
{
if (val == null) return string.Empty;
val = val.Replace("_", "");
StringBuilder sb = new StringBuilder(val.Length + 10);
bool first = true;
char lastChar = '\0';
foreach (char ch in val)
{
if (!first && (char.IsUpper(ch) || char.IsDigit(ch) && !char.IsDigit(lastChar)))
sb.Append(' ');
sb.Append(ch);
first = false;
lastChar = ch;
}
return sb.ToString();
}
Remove the brackets from around the data type name: RETURNS NVARCHAR(MAX)
.删除数据类型名称周围的括号: RETURNS NVARCHAR(MAX)
。 The double brackets mean it's interpreted as a user-defined data type called "NVARCHAR(MAX)" (one word) and quoted because of the parentheses in the name.双括号表示它被解释为一种用户定义的数据类型,称为“NVARCHAR(MAX)”(一个字)并由于名称中的括号而被引用。
If you want to keep brackets for whatever reason, you can do that .如果您想出于任何原因保留括号,您可以这样做。 Move the closing bracket to exclude the (MAX)
like so:移动右括号以排除(MAX)
如下所示:
RETURNS [NVARCHAR](MAX)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.