SQL

SQLServer 创建函数和调用函数

耀世
2023-06-07 / 0 评论 / 27 阅读 / 正在检测是否收录...

创建函数

--创建函数
go
Create Function getAge(@StuID int)
returns int
Begin
 declare @Age int; --返回的参数
 Select @Age=Age from Students where StuID=@StuID; --给参数赋值
 return @Age; --返回值
End
Go

调用函数

Select dbo.getAge(1) as 年龄
Select Sum(Age) as 年龄 From Students
0

评论 (0)

取消