排名
1
文章
860
粉丝
112
评论
163
.net core自定义项目模板,创建自己的模板项目,使用命令行创建模板项目
尘叶心繁 : 可以可以讲真的我都想弄个模板
net core webapi post传递参数
庸人 :
确实坑哈,我也是下班好了好几次,发现后台传递对象是可以的,但...
.net webapi 返回需要的字段,忽略某些字段,修改字段名等
雨雨雨雨雨辰 : 已精
.net webapi 返回需要的字段,忽略某些字段,修改字段名等
雨雨雨雨雨辰 :
疯狂反射
百度编辑器自定义模板
庸人 : 我建议换个编辑器,因为现在百度富文本已经停止维护了,用tinymec...
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:
50010702506256


欢迎加群交流技术

函数
系统自带函数(avg,sum,min,max,count),用户自定义函数
系统分类:
表值函数,标量值函数,聚合函数
函数语法:
函数必须要一个返回值
create function 函数名(参数列表)
returns 返回类型
as
begin
......函数体
return 返回值
end
定义一个函数,没有参数,返回为int
create function func_show()
returns int
as
begin
return 1
end
执行函数
select dbo.函数名
dbo database ower 数据库拥有者
--表值函数(返回一张表的结果)
create function 函数名(参数列表)
returns table
as
return 查询表的结果
下面贴demo
show code
- --定义一个函数,没有参数,返回为int
- create function func_show()
- returns int
- as
- begin
- return 1
- end
-
- select dbo.func_show()
-
- --定义一个函数,有一个参数,有一个返回值,传一个参数输出一句话
- go
- alter function func_print(@msg nvarchar(64))
- returns nvarchar(64)
- as
- begin
- return @msg
- end
-
- select dbo.func_print('hello func')
-
- --定义一个求和的函数,两个参数一个返回值
- create function func_sum(@p1 int,@p2 int)
- returns int
- as
- begin
- return @p1+@p2
- end
- select dbo.func_sum(6,9)
-
-
- select * from UserInfo
-
- --根据用户名查询学号
- alter function func_select(@username nvarchar(64))
- returns nvarchar(64)
- as
- begin
- --定义一个变量
- declare @number_temp nvarchar(64)
- --给变量赋值
- select @number_temp =number from UserInfo where username=@username
-
- if(@number_temp is null)
- return '用户名不存在'
-
- --返回变量
- return @number_temp
-
- end
-
- select dbo.func_select('吕布')
-
-
- =--查询用户表
- alter function func_query(@number nvarchar(64))
- returns table
- as
- return select * from UserInfo where number like '%'+@number+'%'
-
-
- select * from dbo.func_query('002')
-
-
- --系统自带的字符串函数
-
- --截取字符串
- select SUBSTRING('abcdef',4,2)
- --求字符串的长度
- select LEN('abcdef')
- --进一法 3.14--> 4 3.2--> 4
- select CEILING(3.04)
- --去尾法
- select FLOOR(3.9)
-
- --自定义一个函数,一个参数,一个返回值,要求:实现四舍五入,只考虑一个小数
- select my_round(3.6)
-
-
-
- create function my_round(@number nvarchar(64))
- returns int
- as
- begin
- declare @numberTemp int;
- set @numberTemp = SUBSTRING(@number,charindex('.',@number)+1,1)
- return @numberTemp
- end
-
-
- select dbo.my_round('3.64')
欢迎加群讨论技术,1群:677373950(满了,可以加,但通过不了),2群:656732739。有需要软件开发,或者学习软件技术的朋友可以和我联系~(Q:815170684)
评价