SQL “TRIM”不是可识别的内置函数名称
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6814476/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
'TRIM' is not a recognized built-in function name
提问by Shine
I have created simple function
我创建了简单的函数
create function TRIM(@data varchar(20)) returns varchar(100)
as
begin
declare @str varchar(20)
set @str = rtrim(ltrim(@data))
return @str
end
I am executing in the below way.
我正在按以下方式执行。
declare @s varchar(25)
set @s = ' Amru '
select TRIM(@s)
I am getting the following error.
我收到以下错误。
Msg 195, Level 15, State 10, Line 3
'TRIM' is not a recognized built-in function name.
Could any one please help me find the issue?
任何人都可以帮我找到问题吗?
采纳答案by DaveShaw
You need to use the Schema prefix when calling user defined functions. In your case this will most likely be "dbo".
调用用户定义的函数时需要使用 Schema 前缀。在您的情况下,这很可能是“dbo”。
Change your select statement to:
将您的选择语句更改为:
declare @s varchar(25)
set @s = ' Amru '
select dbo.TRIM(@s)
回答by Faraz Ali Siddiqui
//use RTrim instead of Trim sql 2008
RTrim(ColumnName)
RTrim(列名)
like this
像这样
select RTrim(a.ContactName) + ' ' + RTrim(a.City) as Name_City from customers as a
回答by nayanajith
declare @s varchar(25)
set @s = ' Amru '
select RTRIM(LTRIM(@s))
You can use this way also without schema :)
您也可以在没有架构的情况下使用这种方式:)
回答by OsQu
SQL server tries to parse TRIM
as a built-in function. To call user-defined function you should put schema prefix in front of the function call. Try something like:
SQL Server 尝试将其解析TRIM
为内置函数。要调用用户定义的函数,您应该在函数调用之前放置架构前缀。尝试类似:
declare @s varchar(25)
set @s = ' Amru '
select dbo.TRIM(@s)
Since dbo
is a default schema prefix.
因为dbo
是默认模式前缀。
If you want to change your schema, declare the function as follow: (note the schema prefix in front of function name)
如果要更改架构,请按如下方式声明函数:(注意函数名称前面的架构前缀)
create function dbo.TRIM(@data varchar(20)) returns varchar(100)
as
begin
--function body
end
回答by Datajam
The error is that 'TRIM' is not a built-in function in SQL Server (as the error message suggests :) )
错误是“TRIM”不是 SQL Server 中的内置函数(如错误消息所示:))
You can either wrap it with both LTRIM and RTRIM instead, or create your own TRIM function that does the same.
您可以使用 LTRIM 和 RTRIM 来包装它,也可以创建自己的 TRIM 函数来执行相同的操作。