为什么 SQL Server 找不到新创建的函数?

Why newly created functions can not be found by SQL Server?(为什么 SQL Server 找不到新创建的函数?)
本文介绍了为什么 SQL Server 找不到新创建的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道为什么最近我创建了函数,但 SQL Server 在调用它们时返回错误,以防它们被添加到数据库的函数列表中.

I wonder why recently I create functions but SQL Server returns error in calling them, in a case they get added to the functions list of the database.

例如对于以下函数,我得到这样的错误:

For example for the following function I get such a error:

declare @cats nvarchar(1000)
set @cats = 'a|b|c|d|e'

SELECT dbo.fncSplit(@Cats, '|')

错误:

找不到列dbo"或用户定义的函数或聚合dbo.fncSplit",或者名称不明确.

Cannot find either column "dbo" or the user-defined function or aggregate "dbo.fncSplit", or the name is ambiguous.

示例函数:

CREATE FUNCTION [dbo].fncSplit
(    
    @RowData NVARCHAR(MAX),
    @Delimeter NVARCHAR(MAX)
)
RETURNS @RtnValue TABLE 
(
    ID INT IDENTITY(1,1),
    Data NVARCHAR(MAX)
) 
AS
BEGIN 
    DECLARE @Iterator INT
    SET @Iterator = 1

    DECLARE @FoundIndex INT
    SET @FoundIndex = CHARINDEX(@Delimeter,@RowData)

    WHILE (@FoundIndex>0)
    BEGIN
        INSERT INTO @RtnValue (data)
        SELECT 
            Data = LTRIM(RTRIM(SUBSTRING(@RowData, 1, @FoundIndex - 1)))

        SET @RowData = SUBSTRING(@RowData,
                @FoundIndex + DATALENGTH(@Delimeter) / 2,
                LEN(@RowData))

        SET @Iterator = @Iterator + 1
        SET @FoundIndex = CHARINDEX(@Delimeter, @RowData)
    END

    INSERT INTO @RtnValue (Data)
    SELECT Data = LTRIM(RTRIM(@RowData))

    RETURN
END

任何建议或解决方案将不胜感激.

Any suggestion or solution would be highly appreciated.

推荐答案

这是表值函数.语法是

declare @cats nvarchar(1000)
set @cats = 'a|b|c|d|e'

SELECT * from dbo.fncSplit(@Cats, '|')

这篇关于为什么 SQL Server 找不到新创建的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
SSIS: Model design issue causing duplications - can two fact tables be connected?(SSIS:模型设计问题导致重复-两个事实表可以连接吗?)
SQL Server Graph Database - shortest path using multiple edge types(SQL Server图形数据库-使用多种边类型的最短路径)
Invalid column name when using EF Core filtered includes(使用EF核心过滤包括时无效的列名)
How should make faster SQL Server filtering procedure with many parameters(如何让多参数的SQL Server过滤程序更快)
How can I generate an entity–relationship (ER) diagram of a database using Microsoft SQL Server Management Studio?(如何使用Microsoft SQL Server Management Studio生成数据库的实体关系(ER)图?)