SQL中存储过程与自定义函数怎么互相转换?
1个回答
展开全部
--(1):输入一个数,返回结果为这个数加1
--存储过程:
create procedure pro_test
@input int,
@output int output
as
set @output = @input+1
go
--函数:
create function f_test(@input int)
returns int
as
begin
declare @output int
set @output = @input+1
return @output
end
--(2)输入一个数,返回一个结果集
--存储过程:
create procedure pro_test2
@input int
as
select * from sysobjects where id = @input
go
--函数:
create function f_test2(@input int)
returns table
as
return (select * from sysobjects where id = @input)
--存储过程:
create procedure pro_test
@input int,
@output int output
as
set @output = @input+1
go
--函数:
create function f_test(@input int)
returns int
as
begin
declare @output int
set @output = @input+1
return @output
end
--(2)输入一个数,返回一个结果集
--存储过程:
create procedure pro_test2
@input int
as
select * from sysobjects where id = @input
go
--函数:
create function f_test2(@input int)
returns table
as
return (select * from sysobjects where id = @input)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询