将空列表传递给标量函数上的用户定义表类型参数 [英] Passing empty list to user defined table type parameter on a scalar function
问题描述
所以我有这个用户定义的表类型参数,它在我的标量函数中使用并且可能为空.我已阅读有关将空列表传递给存储过程上的表值参数的主题:绑定空列表或存储过程 (.net) 上表值参数的空值
基本上,正如其中一位回复者所说:
So I have this user-defined table type parameter, which is used in my scalar function and might be empty.
I've read this topic about passing empty list to table-valued parameter on a stored procedure:
Binding empty list or null value to table valued parameter on a stored procedure (.net)
And basically, as one of the repliers said:
"诀窍是:根本不传入参数.默认表值参数的值是一个空表"
"The trick is: don’t pass in the parameter at all. The default value for a table-valued parameter is an empty table"
但是,当我在标量函数上尝试此操作时,出现错误:
However, when I try this on scalar function, I get an error:
为过程提供的参数数量不足或功能
An insufficient number of arguments were supplied for the procedure or function
那么如何将空值传递给标量函数上的表值参数?
So how do I pass empty value to table-valued parameter on a scalar function?
推荐答案
函数的参数不是可选的,因此您需要将兼容的 TVP 传递给函数.我不确定我是否理解采用 TVP 类型但不需要的标量值函数的意义 - 这个函数有什么作用,没有 TVP 怎么办?你确定这不是 TVF?
Arguments to functions aren't optional, so you need to pass a compatible TVP to the function. I'm not sure I understand the point of a scalar-valued function that takes a TVP type but doesn't need to - what does this function do and how can it do it without the TVP? Are you sure this isn't meant to be a TVF?
无论如何,这是将空 TVP 传递给标量函数的方法:
Anyway here is how you can pass an empty TVP to a scalar function:
DECLARE @x dbo.TVP_type_name;
SELECT dbo.function_name(@x);
这篇关于将空列表传递给标量函数上的用户定义表类型参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!