MSSQL对函数的调用方法不止一种哦
2006-10-27 21:56
344 查看
首先来建立一个把数据转变成十六进制字符串输出的函数:
CREATE FUNCTION s_hexadecimal
(@binvalue varbinary(255))
RETURNS varchar(255)
AS
BEGIN
declare @charvalue varchar(255)
declare @i int
declare @length int
declare @hexstring char(16)
select @charvalue = '0x'
select @i = 1
select @length = datalength(@binvalue)
select @hexstring = '0123456789abcdef'
while (@i <= @length)
begin
declare @tempint int
declare @firstint int
declare @secondint int
select @tempint = convert(int, substring(@binvalue,@i,1))
select @firstint = floor(@tempint/16)
select @secondint = @tempint - (@firstint*16)
select @charvalue = @charvalue +
substring(@hexstring, @firstint+1, 1) +
substring(@hexstring, @secondint+1, 1)
select @i = @i + 1
end
return @charvalue
END
普通的函数方法是:
select '返回值' = dbo.s_hexadecimal(convert(varbinary(255), 256))
其实也可以这样来调用:
declare @bin varbinary(255)
select @bin = convert(varbinary(255), 1024)
execute s_hexadecimal @bin
select '返回值' = @bin
CREATE FUNCTION s_hexadecimal
(@binvalue varbinary(255))
RETURNS varchar(255)
AS
BEGIN
declare @charvalue varchar(255)
declare @i int
declare @length int
declare @hexstring char(16)
select @charvalue = '0x'
select @i = 1
select @length = datalength(@binvalue)
select @hexstring = '0123456789abcdef'
while (@i <= @length)
begin
declare @tempint int
declare @firstint int
declare @secondint int
select @tempint = convert(int, substring(@binvalue,@i,1))
select @firstint = floor(@tempint/16)
select @secondint = @tempint - (@firstint*16)
select @charvalue = @charvalue +
substring(@hexstring, @firstint+1, 1) +
substring(@hexstring, @secondint+1, 1)
select @i = @i + 1
end
return @charvalue
END
普通的函数方法是:
select '返回值' = dbo.s_hexadecimal(convert(varbinary(255), 256))
其实也可以这样来调用:
declare @bin varbinary(255)
select @bin = convert(varbinary(255), 1024)
execute s_hexadecimal @bin
select '返回值' = @bin
相关文章推荐
- 父类的正常成员函数子类可以使用,并不是继承下来 的,子类是怎么调用父类的函数 : 可能是利用了一种叫函数名联编的方法.没有隐藏的情况下用函数名字来决定调用的函数.
- nios软核cpu中架构类shell的一种解决方式『linux 系统函数调用的方法』
- 编写c51程序调用汇编函数的一种方法
- 学习到了 一种新的函数调用方法
- vb.net一种简单的方法动态调用标准dll中函数
- 调用jupyter notebook文件内的函数一种简单方法
- OpenCV2.2调用highgui函数总是出错,一种可能的解决方法
- 一种显示函数被调用的堆栈信息的方法
- 递归算法是一种直接或者间接调用自身函数或者方法的算法
- JavaScript实现显示函数调用堆栈的方法
- android调用matlab中的函数方法
- js函数常见的写法以及调用方法
- eclipse 中main()函数中的String[] args如何使用?通过String[] args验证账号密码的登录类?静态的主方法怎样才能调用非static的方法——通过生成对象?在类中制作一个方法——能够修改对象的属性值?
- 换一种思路实现c调用lua函数
- 调用Excel中的函数的方法
- TMS320F28335 调用DSP函数库实现复数的FFT的方法
- 浅析将matlab函数编译成dll供Cpp调用的方法
- java中如何跳出多重循环,方法不止break一种
- 动态调用非托管MFC动态链接库中函数的方法封装。