programing

열 "dbo" 또는 사용자 정의 함수 또는 집계 "dbo"를 찾을 수 없습니다.splitfn" 또는 이름이 모호함

telebox 2023. 8. 15. 11:02
반응형

열 "dbo" 또는 사용자 정의 함수 또는 집계 "dbo"를 찾을 수 없습니다.splitfn" 또는 이름이 모호함

다음 분할 기능을 사용했습니다.

CREATE FUNCTION dbo.Splitfn(@String varchar(8000), @Delimiter char(1))       
returns @temptable TABLE (items varchar(8000))       
 as       
begin       
declare @idx int       
declare @slice varchar(8000)       
  
select @idx = 1       
    if len(@String)<1 or @String is null  return       
  
while @idx!= 0       
begin       
    set @idx = charindex(@Delimiter,@String)       
    if @idx!=0       
        set @slice = left(@String,@idx - 1)       
    else       
        set @slice = @String       
      
    if(len(@slice)>0)  
        insert into @temptable(Items) values(@slice)       

    set @String = right(@String,len(@String) - @idx)       
    if len(@String) = 0 break       
end   
return      

end  

그리고 나는 이 기능을 쿼리에 사용했고 그것은 실행되었습니다.

ALTER PROCEDURE [dbo].[Employees_Delete] 
-- Add the parameters for the stored procedure here
@Id varchar(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here

 if exists( select Emp_Id from Employee where Emp_Id=dbo.Splitfn(@Id,','))
begin
    update Employee set Is_Deleted=1 where Emp_Id=dbo.Splitfn(@Id,',')
    select 'deleted' as message
end 
END

하지만 제가 (1,2)라고 말하는 값을 주는 스토어 절차를 실행할 때 오류가 발생했습니다.

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

테이블 값 함수인 'splitfn'을 확인했는데 무엇이 잘못되고 있는지 알 수 없습니다.어떤 제안이든..

테이블 값 함수이지만 스칼라 함수로 사용하고 있습니다.

시도:

where Emp_Id IN (SELECT i.items FROM dbo.Splitfn(@Id,',') AS i)

하지만... 기능을 인라인 TVF로 변경하는 것도 고려해 보십시오. 성능이 더 좋을 것입니다.

테이블 값 udf를 테이블처럼 취급해야 합니다(예: 조인).

select Emp_Id 
from Employee E JOIN dbo.Splitfn(@Id,',') CSV ON E.Emp_Id = CSV.items 

일반적인 대답

select * from [dbo].[SplitString]('1,2',',') -- Will work 

그렇지만

select [dbo].[SplitString]('1,2',',')  -- will **not** work and throws this error

Google에서 사람들이 오기 때문에 올바른 데이터베이스에 있는지 확인합니다.

'master' 데이터베이스에서 SQL을 실행하면 이 오류가 반환되는 경우가 많습니다.

Database -> Tables -> Functions -> Scalar Valued Functions - dbo.funcName 
rightClick => Properties -> Search UserRoles + Add user access

enter image description here

언급URL : https://stackoverflow.com/questions/2091830/cannot-find-either-column-dbo-or-the-user-defined-function-or-aggregate-dbo-s

반응형