sql 全角 半角
来源:互联网 发布:mac php环境搭建 编辑:程序博客网 时间:2024/06/05 22:51
----------使用自定义函数进行转换
if object_id(N'U_ConvertSBCANDDBC',N'FN') is not null
drop function U_ConvertSBCANDDBC
GO
/*
转换原理
全角字符unicode编码从65281~65374
半角字符unicode编码从33~126
空格比较特殊,全角为 12288,半角为 32
而且除空格外,全角/半角按unicode编码排序在顺序上是对应的
所以可以直接通过用+-法来处理非空格数据,对空格单独处理
like的时候,指定排序规则 COLLATE Latin1_General_BIN
是保证字符顺序按unicode编码排序
*/
create function U_ConvertSBCANDDBC
(
@str nvarchar(4000), --要转换的字符串
@flag bit --转换标志,0转换成半角,1转换成全角
)
returns nvarchar(4000)
AS
begin
declare
@pat nvarchar(8),
@step int,
@i int,
@spc int
if @flag=0
begin
select @pat=N'%[!-~]%',@step=-65248,
@str=replace(@str,N' ',N' ')
end
else
begin
select @pat=N'%[!-~]%',@step=65248,
@str=replace(@str,N' ',N' ')
end
set @i=patindex(@pat collate LATIN1_GENERAL_BIN,@str)
while @i>0
select @str=replace(@str,
substring(
@str,@i,1),
nchar(unicode(substring(@str,@i,1))+@step)),
@i=patindex(@pat collate LATIN1_GENERAL_BIN,@str)
return(@str)
end
GO
if object_id(N'U_ConvertSBCANDDBC',N'FN') is not null
drop function U_ConvertSBCANDDBC
GO
/*
转换原理
全角字符unicode编码从65281~65374
半角字符unicode编码从33~126
空格比较特殊,全角为 12288,半角为 32
而且除空格外,全角/半角按unicode编码排序在顺序上是对应的
所以可以直接通过用+-法来处理非空格数据,对空格单独处理
like的时候,指定排序规则 COLLATE Latin1_General_BIN
是保证字符顺序按unicode编码排序
*/
create function U_ConvertSBCANDDBC
(
@str nvarchar(4000), --要转换的字符串
@flag bit --转换标志,0转换成半角,1转换成全角
)
returns nvarchar(4000)
AS
begin
declare
@pat nvarchar(8),
@step int,
@i int,
@spc int
if @flag=0
begin
select @pat=N'%[!-~]%',@step=-65248,
@str=replace(@str,N' ',N' ')
end
else
begin
select @pat=N'%[!-~]%',@step=65248,
@str=replace(@str,N' ',N' ')
end
set @i=patindex(@pat collate LATIN1_GENERAL_BIN,@str)
while @i>0
select @str=replace(@str,
substring(
@str,@i,1),
nchar(unicode(substring(@str,@i,1))+@step)),
@i=patindex(@pat collate LATIN1_GENERAL_BIN,@str)
return(@str)
end
GO
- SQL全角半角互换
- SQL全角半角转换
- sql 全角 半角
- SQL 全角转半角
- sql 全角转半角
- SQL区分全角/半角
- sql 全角半角的转换
- SQL 全角和半角转换
- SQL将全角转半角
- ORACLE SQL半角全角转换
- SQL SERVER不认全角和半角
- SQL Server 2000半角全角转换
- sql 半角 全角 传化函数
- SQL SERVER 全角和半角的解决方法
- sql 半角 全角 传化函数
- sql 全角字符,半角字符查询
- SQL 半角与全角之间转换
- SQL为啥不分半角与全角?
- Js offsetTop、offsetParent...
- COM载板设计之二:电源与复位
- Mock-jmock&easymock 小凯总结
- 电子罗盘HMC5883L WICE6.0驱动实现
- Spring 批量处理文件 ResourcePatternResolver
- sql 全角 半角
- js函数的几种写法
- js中获取Fckeditor的值
- 静态页面加载静态页面代码
- 快速遍历SDcard下面的所有文件
- linux远程登录
- C++数值与字符串相互转换的那些事(一)字符串转数值(转载请注明)
- iptables 配置防火墙
- 嘿宝宝,妈妈得奖金了