当前位置:首页 » 编程语言 » sql拼音函数
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

sql拼音函数

发布时间: 2022-01-18 09:37:35

sql存储过程获取汉字拼音头字母函数

复制代码
代码如下:
--函数
CREATE
function
fn_GetPy(@str
nvarchar(4000))
returns
nvarchar(4000)
--WITH
ENCRYPTION
as
begin
declare
@intLenint
declare
@strRetnvarchar(4000)
declare
@temp
nvarchar(100)
set
@intLen
=
len(@str)
set
@strRet
=
''
while
@intLen
>
0
begin
set
@temp
=
''
select
@temp
=
case
when
substring(@str,@intLen,1)
>=
'帀'
then
'Z'
when
substring(@str,@intLen,1)
>=
'丫'
then
'Y'
when
substring(@str,@intLen,1)
>=
'夕'
then
'X'
when
substring(@str,@intLen,1)
>=
'屲'
then
'W'
when
substring(@str,@intLen,1)
>=
'他'
then
'T'
when
substring(@str,@intLen,1)
>=
'仨'
then
'S'
when
substring(@str,@intLen,1)
>=
'呥'
then
'R'
when
substring(@str,@intLen,1)
>=
'七'
then
'Q'
when
substring(@str,@intLen,1)
>=
'妑'
then
'P'
when
substring(@str,@intLen,1)
>=
'噢'
then
'O'
when
substring(@str,@intLen,1)
>=
'拏'
then
'N'
when
substring(@str,@intLen,1)
>=
'呒'
then
'M'
when
substring(@str,@intLen,1)
>=
'垃'
then
'L'
when
substring(@str,@intLen,1)
>=
'咔'
then
'K'
when
substring(@str,@intLen,1)
>=
'丌'
then
'J'
when
substring(@str,@intLen,1)
>=
'铪'
then
'H'
when
substring(@str,@intLen,1)
>=
'旮'
then
'G'
when
substring(@str,@intLen,1)
>=
'发'
then
'F'
when
substring(@str,@intLen,1)
>=
'妸'
then
'E'
when
substring(@str,@intLen,1)
>=
'咑'
then
'D'
when
substring(@str,@intLen,1)
>=
'嚓'
then
'C'
when
substring(@str,@intLen,1)
>=
'八'
then
'B'
when
substring(@str,@intLen,1)
>=
'吖'
then
'A'
else
rtrim(ltrim(substring(@str,@intLen,1)))
end
--对于汉字特殊字符,不生成拼音码
if
(ascii(@temp)>127)
set
@temp
=
''
--对于英文中小括号,不生成拼音码
if
@temp
=
'('
or
@temp
=
')'
set
@temp
=
''
select
@strRet
=
@temp
+
@strRet
set
@intLen
=
@intLen
-
1
end
return
lower(@strRet)
end
go
--调用
select
dbo.fn_getpy('张三')
--返回:zs
答!:
2:
取汉字拼音首字母的存储过程
Create
function
fun_getPY
(
@str
nvarchar(4000)
)
returns
nvarchar(4000)
as
begin
declare
@word
nchar(1),@PY
nvarchar(4000)
set
@PY=''
while
len(@str)>0
begin
set
@word=left(@str,1)
--如果非汉字字符,返回原字符
set
@PY=@PY+(case
when
unicode(@word)
between
19968
and
19968+20901
then
(
select
top
1
PY
from
(
select
'A'
as
PY,N'骜'
as
word
union
all
select
'B',N'簿'
union
all
select
'C',N'错'
union
all
select
'D',N'鵽'
union
all
select
'E',N'樲'
union
all
select
'F',N'鳆'
union
all
select
'G',N'腂'
union
all
select
'H',N'夻'
union
all
select
'J',N'攈'
union
all
select
'K',N'穒'
union
all
select
'L',N'鱳'
union
all
select
'M',N'旀'
union
all
select
'N',N'桛'
union
all
select
'O',N'沤'
union
all
select
'P',N'曝'
union
all
select
'Q',N'囕'
union
all
select
'R',N'鶸'
union
all
select
'S',N'蜶'
union
all
select
'T',N'箨'
union
all
select
'W',N'鹜'
union
all
select
'X',N'鑂'
union
all
select
'Y',N'韵'
union
all
select
'Z',N'咗'
)
T
where
word>=@word
collate
Chinese_PRC_CS_AS_KS_WS
order
by
PY
ASC
)
else
@word
end)
set
@str=right(@str,len(@str)-1)
end
return
@PY
end

Ⅱ sql server根据名字生成拼音,怎么做

sql server自动生成拼音首字母的函数
http://blog.csdn.net/luckeryin/article/details/3377378

Ⅲ SQL SERVER 获取字符串拼音函数,求优化

按你这种写法看起来优化程度有限。可以考虑吧substring改成left。每次循环完把第一个字符去掉。可能比substring 快点。

另外有个思路。就是需要替换成字母的字已经是确认的了。我数了一下是23个字
那你循环23遍 吧对应的字替换成对应的字母。 这样循环次数就固定下来,应该比传进来的字符串一个个循环次数少 。效率肯定会高!

Ⅳ sql 汉字转拼音,若有重复的在拼音加1

题主意思,表a已经有字段hz,现在要更新py这列?这样的话,只要update就行了,为什么说最好是函数实现呢?还是说题主想要selecthz,func(hz)froma这样的呢?

函数。

首先需要一个解析汉字到拼音的方法,这里有一个包,你可以复制过去直接执行。

脚本地址:

http://www.cnblogs.com/mellowsmile/p/4601288.html

附代码:

--不是我不贴,代码太多贴不上,题主还是去上面那个地址复制吧,注意复制全部。


在SQL窗口执行。

我这里建了一个测试表test,数据显示如下:

select a.* from test a;

题主,如此,可否?

Ⅳ SQL语句提取出中文的拼音首字母

正好最近收藏了一个 你可以看下思路
--将中文字符串转化成文字首拼音的组合
create function fun_getPY(@str nvarchar(4000))
returns nvarchar(4000)
as
begin
declare @word nchar(1),@PY nvarchar(4000)
set @PY=''
while len(@str)>0
begin
set @word=left(@str,1)
--如果非汉字字符,返回原字符
set @PY=@PY+(case when unicode(@word) between 19968 and 19968+20901
then (select top 1 PY from (
select 'A' as PY,N'骜' as word
union all select 'B',N'簿'
union all select 'C',N'错'
union all select 'D',N'鵽'
union all select 'E',N'樲'
union all select 'F',N'鳆'
union all select 'G',N'腂'
union all select 'H',N'夻'
union all select 'J',N'攈'
union all select 'K',N'穒'
union all select 'L',N'鱳'
union all select 'M',N'旀'
union all select 'N',N'桛'
union all select 'O',N'沤'
union all select 'P',N'曝'
union all select 'Q',N'囕'
union all select 'R',N'鶸'
union all select 'S',N'蜶'
union all select 'T',N'箨'
union all select 'W',N'鹜'
union all select 'X',N'鑂'
union all select 'Y',N'韵'
union all select 'Z',N'咗'
) T
where word>=@word collate Chinese_PRC_CS_AS_KS_WS
order by PY ASC) else @word end)
set @str=right(@str,len(@str)-1)
end
return @PY
end
--函数调用实例:
select dbo.fun_getPY('中华人民共和国AAA01')

/*

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ZHRMGHGAAA01

(1 行受影响)

*/

Ⅵ sql批量生成拼音码问题

1
创建这个函数。
Create

function fun_getPY
(
@str
nvarchar(4000)
)

returns

nvarchar(4000)
as

begin

declare

@word nchar(1),@PY nvarchar(4000)
set

@PY=''
while

len(@str)>0
begin

set

@word=left(@str,1)
--
set

@PY = @PY+(casewhenunicode(@word)between 19968 and 19968+20901

then (
select

top 1 PY
from

(

select

'A'as PY,N''as word
union

allselect'B',N''
union

allselect'C',N''
union

allselect'D',N''
union

allselect'E',N''
union

allselect'F',N''
union

allselect'G',N''
union

allselect'H',N''
union

allselect'J',N''
union

allselect'K',N''
union

allselect'L',N''
union

allselect'M',N''
union

allselect'N',N''
union

allselect'O',N''
union

allselect'P',N''
union

allselect'Q',N''
union

allselect'R',N''
union

allselect'S',N''
union

allselect'T',N''
union

allselect'W',N''
union

allselect'X',N''
union

allselect'Y',N''
union

allselect'Z',N''
)

T
where

word>=@word collate Chinese_PRC_CS_AS_KS_WS
order

by PY ASC
)

else

@word
end

)
set

@str=right(@str,len(@str)-1)
end

return

@PY
end

2
select dbo.fun_getPY(该字段) from 表

Ⅶ 如果我要加一些数据的拼音进数据库,SQL语句怎么写啊

sql函数返回拼音码/五笔码/自定义码
2009-02-23 09:27
if exists(select * from sysobjects where name='fun_get_bm') drop function fun_get_bm
go

create function fun_get_bm(@str nvarchar(4000),@srm varchar(20))
returns nvarchar(4000)
as
begin
declare @word nchar(1),@PY nvarchar(4000)
set @PY=''
while len(@str)>0
begin
set @word=left(@str,1)
--如果非汉字字符,返回原字符
set @PY=@PY+(case when unicode(@word) between 19968 and 19968+20901
then (select top 1 PY from (select top 1 case
when @srm='1' then srm1
when @srm='2' then srm2
else srm3
end as PY,word from xt_hzk where word=@word
) T
where word>=@word collate Chinese_PRC_CS_AS_KS_WS
order by PY ASC) else @word end)
set @str=right(@str,len(@str)-1)
end
return replace(replace(@PY,' ',''),'$','')
end
go

--xt_hzk这个表是我们自己写的汉字库表

--用法如

select dbo.fun_get_bm('张三丰','1')

--参数第一个编译的值,第二个传递1[拼音码],2[五笔码],3[自定义码]

输出 ZSF

贴过来的 参考 呵呵

Ⅷ 汉字转拼音的sql函数为什么用到这些字 :骜簿错鵽樲鳆腂夻攈穒鱳旀桛沤曝囕鶸蜶箨鹜鑂韵咗,求原理

没人回答,自己找到了答案,整个sql排序规则是按照拼音排序, 以此句sql为例:'A' AS PY,N'骜' AS word ”骜“字代表的是以A开头的拼音,并且音调是也要排最后的一个字,读做“ào”,所以得出在这个区间的汉字首字母都为A,以此类推可查出其他字母开头的汉字首字母

Ⅸ 如何用db2的sql写一个获取汉字拼音首字母的

DECLARE @str VARCHAR(100)
SET @str = '汉字的首字母'
SELECT @str AS A, dbo.fun_getPY(@str) AS B

先执行上面的那个函数,然后在执行下面的那个语句,就可以得到你要的结果了。

Ⅹ sql中怎样按拼音排序

如果只是英文和数字的可以试试下面的方法:
在ORACLE SQL中有这样一个函数ASCII(char)

ASCII(char)的参数可以为字符串
例如:
select ASCII('D'), ASCII('Dave') FROM al
返回为:
ASCII('D') ASCII('Dave')
---------------------------
68 68

不知道这些对你有帮助没