标量值函数可以从 .NET 调用,如下所示:

SqlCommand cmd = new SqlCommand("testFunction", sqlConn); //testFunction is scalar
cmd.CommandType = CommandType.StoredProcedure;  
cmd.Parameters.Add("retVal", SqlDbType.Int);
cmd.Parameters["retVal"].Direction = ParameterDirection.ReturnValue;
cmd.ExecuteScalar();
int aFunctionResult = (int)cmd.Parameters["retVal"].Value;

我还知道可以以类似的方式调用表值函数,例如:

String query = "select * from testFunction(param1,...)"; //testFunction is table-valued
SqlCommand cmd = new SqlCommand(query, sqlConn);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
adapter.Fill(tbl);

我的问题是,表值函数是否可以像标量值函数一样作为存储过程调用?(例如,使用被调用的表值函数复制我的第一个代码片段,并通过 ReturnValue 参数获取返回的表)。

有帮助吗?

解决方案

不,因为您需要选择它们。但是,您可以创建一个存储过程包装器,这可能会破坏表函数的意义。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top