我可以在Function(UDF)和viseversa中调用存储过程吗? [英] Can i call Stored Procedure with in Function(UDF) and viseversa?

查看:83
本文介绍了我可以在Function(UDF)和viseversa中调用存储过程吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在SQL SERVER中用Function(UDF)调用存储过程吗?如果可能的话,请使用较小的exp ...

Can i call Stored Procedure with in Function(UDF) in SQL SERVER vice versa ? if possible explain with small exp...

推荐答案

是的,我们可以在SP中调用UDF,但不能反向调用.

详细信息:
如果您知道SP,我们可以在其中编写多个查询.调用UDF就像只编写一个Select查询一样.因此,您可以使用参数来调用UDF,而不是调用表.完成!

如果您知道UDF,则可以确定无法在其中调用SP.
Yes we can call UDF in a SP but not the reverse.

Details:
If you know SP, we can write multiple queries in it. Calling a UDF is just like writing a Select query only. So instead of calling a table, you call UDF with parameters. Done!

If you know UDF''s then you can make out that there is no way you can call SP in it.


当我尝试从函数执行存储过程时,我得到: 只能从函数内部执行函数和扩展存储过程."不过,这可能取决于SQL Server的版本.

但是,您可以从存储过程中调用函数:
When I try to execute a stored procedure from a function, I get: "Only functions and extended stored procedures can be executed from within a function." That might depend on the version of SQL Server though.

You can, however, call a function from a stored procedure:
CREATE FUNCTION dbo.fn_DoubleValue
(
    @val as int
)
RETURNS int
BEGIN
	RETURN @val * 2
END

GO

CREATE PROCEDURE ValueTimes4
	@val as int
AS
BEGIN
    SELECT dbo.fn_DoubleValue(dbo.fn_DoubleValue(@val))
END

GO

EXEC ValueTimes4 4


这篇关于我可以在Function(UDF)和viseversa中调用存储过程吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆