当前位置:首页 » 编程语言 » 创建sql自定义函数

创建sql自定义函数

发布时间: 2023-05-08 15:08:51

❶ 什么是sql自定义函数

Create Function myFunc(@param1 int,@param2 varchar(50)) returns int
as
begin
......
RETURN 0
end
类似这样自己建的函数,就是SQL自定义函数,可以自定义参数和返回值的,能够在查询语句中使用的。
像max(),min(),getdate(),newid()这些就是系统函数了。

❷ sqlserver中自定义函数

创建自定义缺缓函数:
use 数祥扮猛据谨桥库名
go
create function 函数名
(@pno int)
returns int
as
begin
declare @a int
if not exists(select * from person where pno=@pno)
set @a=-1
else
set @a=1
return @a
end

调用函数:
use 数据库
go
select dbo.函数名(13250)

❸ SQL建自定义函数

一个简单的自定义求和函拍瞎数
create Function sumnum(@A INT,@B int)
Returns int
As
Begin
Declare
@S int
Set @S='袭轿空'
Select @S=@A+@B
Return (@S)
End

--测试帆粗
--SELECT DBO.sumnum(1,2)

❹ SQL中创建一个用户自定义函数

CREATE
FUNCTION
DBO.tFProctsHS
(
@name
VARCHAR(10))
RETURNS
INT
--这个根据价格的类型自己修改
AS
begin
DECLARE
@jiage
INT;
select
@jiage=
jiage
from
商品表
where
name=
@name
RETURN
(@jiage)
end
--ceshi
select
DBO.tFProctsHS
('记事本')

❺ SQL创建用户自定义函数

楼主我只写了其中一个..基本方法都如此,希望对您有帮助,代码如下

ALTER FUNCTION [dbo].[sum]
(
@class varchar(100), --所选课程
@username varchar(20) --学生姓名
)
RETURNS int
AS
BEGIN
DECLARE @reun int
SELECT SUN(@class) FROM YOURTABLE WHERE USERNAME=@username
RETURN @reun

END

❻ Microsoft SQL Server如何创建 自定义函数

Create Function RmGetPY(@chn nchar(1))
returns char(1)
as
begin
declare @n int
declare @c char(1)
set @n = 63
select @n = @n +1,@c = case chn when @chn then char(@n) else @c end from(
select top 27 * from (
select chn =
'吖' union all select
'八' union all select
'嚓' union all select
'咑' union all select
'妸' union all select
'发' union all select
'旮' union all select
'铪' union all select
'丌' union all select
'丌' union all select
'咔' union all select
'垃' union all select
'呒' union all select
'拏' union all select
'噢' union all select
'妑' union all select
'七' union all select
'呥' union all select
'仨' union all select
'他' union all select
'屲' union all select
'屲' union all select
'屲' union all select
'夕' union all select
'丫' union all select
'帀' union all select @chn) as a
order by chn COLLATE Chinese_PRC_CI_AS
) as b
return(@c)
end

go

Create Function GetAllPY(@chn nvarchar(100))
returns varchar(30)
as
begin

declare @i int,@j int,@result varchar(100)
set @result=''
set @i=len(@chn)
set @j=1
while @j<=@i
begin
set @result = @result + dbo.RmGetPY(substring(@chn,@j,1))
set @j=@j+1
end
return @result
end

看看这两个,典型的取汉字拼音码的函数

❼ sql 创建自定义函数

create function grade_fun
(
@学生 decimail(18,1)
)
returns decimail(18,1)
as
begin
declare @a decimail(18,1)
select @a=sum(grade) from 成绩庆猜团表誉橘兆仿 where 学生=@学生
return @a
end

❽ 写一个Sql自定义函数

declare @flag int,@no varchar(20),@return int
--先为变量赋值
--set @flag=0...
select @return = search1(@flag,@no)

我没明白,是要写函数的代码还是写调用的代码?调用方法上面已写。

热点内容
php办公系统 发布:2025-07-19 03:06:35 浏览:894
奥德赛买什么配置出去改装 发布:2025-07-19 02:53:18 浏览:37
请与网络管理员联系请求访问权限 发布:2025-07-19 02:37:34 浏览:184
ipad上b站缓存视频怎么下载 发布:2025-07-19 02:32:17 浏览:839
phpcgi与phpfpm 发布:2025-07-19 02:05:19 浏览:522
捷达方向机安全登录密码是多少 发布:2025-07-19 00:57:37 浏览:689
夜魔迅雷下载ftp 发布:2025-07-19 00:39:29 浏览:97
增值税票安全接入服务器地址 发布:2025-07-19 00:20:45 浏览:482
solidworkspcb服务器地址 发布:2025-07-18 22:50:35 浏览:820
怎么在堆叠交换机里配置vlan 发布:2025-07-18 22:42:35 浏览:627