Sqlserver 自定义实用函数集(不定期更新)

Sqlserver 自定义实用函数集(不定期更新),第1张

概述1. 删除字符串中符合正规表达的字符 CREATE FUNCTION fun_regex_del ( @inStr VARCHAR(MAX), @expression VARCHAR(MAX))RETURNS VARCHAR(MAX)ASBEGIN DECLARE @str_userlist VARCHAR(MAX); SET @str_userlist 1. 删除字符串中符合正规表达的字符
CREATE FUNCTION fun_regex_del (    @inStr VARCHAR(MAX),@Expression VARCHAR(MAX))RETURNS VARCHAR(MAX)ASBEGIN    DECLARE @str_userList VARCHAR(MAX);    SET @str_userList = @inStr;    DECLARE @i INT;    SET @i = 0;    WHILE PATINDEX(@Expression,@str_userList) > 0      BEGIN          SET @i = PATINDEX(@Expression,@str_userList)          SET @str_userList = STUFF(@str_userList,@i,1,'')      END       RETURN @str_userList;ENDGO
2. URLDecode
CREATE FUNCTION [dbo].[SP_fnURLDecode] ( @input NVARCHAR(4000) ) RETURNS NVARCHAR(4000) AS BEGIN DECLARE @char NVARCHAR(4) DECLARE @asc NVARCHAR(4) DECLARE @asc2 NVARCHAR(4) WHILE ( CHARINDEX('%',@input) > 0 ) BEGIN SET @char = ( SELECT SUBSTRING(@input,CHARINDEX('%',@input) + 1,2) ) IF ( ISNUMERIC(SUBSTRING(@char,1)) ) > 0 BEGIN SET @asc = ( SELECT CAST(SUBSTRING(@char,1) AS INT) ) * 16 END ELSE BEGIN SET @asc = ( SELECT ASCII(CAST(SUBSTRING(@char,1) AS CHAR)) ) - 55 SET @asc = ( SELECT @asc * 16 ) END IF ( ISNUMERIC(SUBSTRING(@char,2,1)) ) > 0 SET @asc = ( SELECT CAST(@asc AS INT) + ( SELECT CAST(SUBSTRING(@char,1) AS INT) ) ) ELSE BEGIN SET @asc2 = ( SELECT ASCII(CAST(SUBSTRING(@char,1) AS CHAR)) ) - 55 SET @asc = ( SELECT CAST(@asc AS INT) + ( SELECT CAST(@asc2 AS INT) ) ) END SET @input = ( SELECT SUBSTRING(@input,0,@input)) ) + CHAR(@asc) + ( SELECT SUBSTRING(@input,@input) + 3,LEN(@input)) ) END RETURN @input END GO
总结

以上是内存溢出为你收集整理的Sqlserver 自定义实用函数集(不定期更新)全部内容,希望文章能够帮你解决Sqlserver 自定义实用函数集(不定期更新)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1172984.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存