当前位置:网站首页>SQL Server 常用函数
SQL Server 常用函数
2022-06-22 12:38:00 【KingCruel】
1、首字母大写
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create FUNCTION [dbo].[CAP_FIRST] ( @InputString varchar(4000) )
RETURNS VARCHAR(4000) AS BEGIN
DECLARE @Index INT DECLARE @Char CHAR(1) DECLARE
@PrevChar CHAR(1) DECLARE @OutputString VARCHAR(255)
SET @OutputString = LOWER(@InputString) SET @Index = 1
WHILE @Index <= LEN(@InputString) BEGIN
SET @Char = SUBSTRING(@InputString, @Index, 1)
SET @PrevChar = CASE WHEN @Index = 1 THEN ' '
ELSE SUBSTRING(@InputString, @Index - 1, 1)
END
IF @PrevChar IN (' ', ';', ':', '!', '?', ',', '.', '_', '-', '/', '&', '''', '(')
BEGIN
IF @PrevChar != '''' OR UPPER(@Char) != 'S'
SET @OutputString = STUFF(@OutputString, @Index, 1, UPPER(@Char))
END
SET @Index = @Index + 1 END
RETURN @OutputString
END
GO*、CAP_FIRST调用
select dbo.CAP_FIRST('abcd_abcd')
select replace(dbo.CAP_FIRST('abcd_abcd'),'_','')*、首字母大写
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create function [dbo].[F_split](@s nvarchar(1000))
returns nvarchar(1000)
as
begin
declare @str nvarchar(1000),@split nvarchar(100)
select @[email protected]+' ',@str=''
while charindex(' ',@s)>0
begin
set @split=left(@s,charindex(' ',@s))
set @[email protected]+upper(left(@split,1))+right(@split,len(@split))
set @s=stuff(@s,1,charindex(char(32),@s),'')
end
return @str
end
GO*、编码转换UrlEncode
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[UrlEncode]
(
@Param NVARCHAR(2000)
)
RETURNS VARCHAR(MAX)
AS
BEGIN
DECLARE @HexStr VARCHAR(MAX)
--Use system function to convert input string to hex string
SET @HexStr = master.dbo.fn_varbintohexstr(CONVERT(VARBINARY(MAX), @Param))
--Remove the starting '0x'
SET @HexStr = RIGHT(@HexStr, LEN(@HexStr)-2)
--Declare required variables
DECLARE @I INT, @Len INT
DECLARE @Output VARCHAR(MAX), @S CHAR(4), @C CHAR(1)
DECLARE @LoByte TINYINT, @HiByte TINYINT
--Get length
SET @Len=LEN(@HexStr)/4
--Start with first character
SET @I=0
--Prepare the output string
SET @Output=''
WHILE @I<@Len
BEGIN
SET @S=SUBSTRING(@HexStr, @I*4 + 1, 4)
IF RIGHT(@S, 2)='00'
BEGIN
--Try to convert 2 hex digits to char
SET @LoByte = ASCII(SUBSTRING(@S, 2, 1)) - 48
IF @LoByte>10 SET @LoByte = @LoByte - 39 --0x61'a'-> 10
SET @HiByte = ASCII(SUBSTRING(@S, 1, 1)) - 48
IF @HiByte>10 SET @HiByte = @HiByte - 39
SET @C=CHAR(@LoByte + @HiByte * 16)
--If it's a reserved character, don't encode
IF @C LIKE '[A-Za-z0-9()''*-._! ]'
SET @Output = @Output + @C
ELSE
SET @Output = @Output + '%' + LEFT(@S, 2)
END
ELSE
SET @Output = @Output + '%u' + RIGHT(@S, 2) + LEFT(@S, 2)
--Move to next hex
SET @I = @I + 1
END
RETURN @Output
END
GO
--select dbo.FN_URLDecode('%E5%B9%BF%E4%B8%9C%E7%9C%81%E7%8F%A0%E6%B5%B7%E5%B8%82%E4%BF%A1%E6%81%AF%E5%B7%A5%E7%A8%8B%E6%9C%89%E9%99%90%E5%85%AC%E5%8F%B8')
GO*
*
*
*
*
*
边栏推荐
猜你喜欢

769. Max Chunks To Make Sorted

别再用 System.currentTimeMillis() 统计耗时了,太 Low,StopWatch 好用到爆!

Redis active / standby configuration dockercompose version

Problème de sous - séquence / substrat leetcode

SSM based community garbage classification and transportation management system, high-quality graduation thesis example (can be used directly), source code, database script, project introduction and o

Uninstall MySQL 8

File download vulnerability & file read vulnerability & file delete vulnerability

Configuring cplex12.4 tutorial in VS2010

“不敢去怀疑代码,又不得不怀疑代码”记一次网络请求超时分析

RCE&代码执行漏洞
随机推荐
leetcode-并查集
[cloud native] event publishing and subscription in Nacos -- observer mode
Istio服务网格中的流量复制
Tables converting to latex format
leetcode 85. Max rectangle
hw在即,你还不会看危险报文?
Performance of recommender algorithms on top-N recommendation tasks
基于SSM的图书馆管理系统,高质量毕业论文范例(可直接使用),项目导入视频,附送源码和数据库脚本,论文撰写教程
Locks in MySQL
openGauss数据库源码解析系列文章—— 密态等值查询技术详解
Interpretation of the thesis -- factorization meets the neighborhood: a multifaceted collaborative filtering model
Writing a contract testing tool from scratch -- database design
310. Minimum Height Trees
Oracle user space statistics
Windows下MySQL 8.0.29的详细安装教程,解决找不到VCRUNTIME140_1.dll、plugin caching_sha2_password could not be loaded
Leetcode math problems
Record of problems encountered in dual network card binding
【云原生】Nacos中的事件发布与订阅--观察者模式
文件下载漏洞&文件读取漏洞&文件删除漏洞
基于SSM的小区垃圾分类和运输管理系统,高质量毕业论文范例(可直接使用),源码,数据库脚本,项目导入运行视频教程,论文撰写教程