sql漢字首字母
Ⅰ sql語句提取出中文的拼音首字母
那我估計不行。
只能把漢字的拼音,存在另一個欄位。
當然你也寫個對照表。
如:
張 zhang
這樣,你插入時,也把zhang插入到拼音欄位里(你自己定義的varchar)。
張三 zhang;san //用分號來分隔
做查詢時把zhang;san 用數組來存儲,接著讀取第一個下標的首字母。
(jsp、asp:split() 就行,php沒學過 )
Ⅱ sql 查詢不重復並且按照漢字首字母排序
select distinct 聯賽分類 from inf order by 聯賽分類
這樣不就可以了,默認本來就是根據首個字元排序的,中文就是根據字母排序的
Ⅲ sql 如何按照漢字的拼音的首字母順序來查詢!~!~
欄位1內的數據是漢字
最後在where查詢語句的後面加上
order by 欄位1 就可以了
補充:
order by 是排序
order by 欄位1 desc 為倒序
Ⅳ sql中怎麼根據漢字的拼音首字母查詢
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
-- SQLServer:
---測試數據---
if object_id('[pactinfo]') is not null drop table [pactinfo]
go
create table [pactinfo]([ID] int,[pactname] varchar(4))
insert [pactinfo]
select 1,'正常' union all
select 2,'中國' union all
select 3,'做飯' union all
select 4,'加發'
---引用前輩們的一個函數---
create function f_GetPy(@str nvarchar(4000))
returns nvarchar(4000)
as
begin
declare @strlen int,@re nvarchar(4000)
declare @t table(chr nchar(1) collate Chinese_PRC_CI_AS,letter nchar(1))
insert into @t(chr,letter)
select '吖 ', 'A ' union all select '八 ', 'B ' union all
select '嚓 ', 'C ' union all select '咑 ', 'D ' union all
select '妸 ', 'E ' union all select '發 ', 'F ' union all
select '旮 ', 'G ' union all select '鉿 ', 'H ' union all
select '丌 ', 'J ' union all select '咔 ', 'K ' union all
select '垃 ', 'L ' union all select '嘸 ', 'M ' union all
select '拏 ', 'N ' union all select '噢 ', 'O ' union all
select '妑 ', 'P ' union all select '七 ', 'Q ' union all
select '呥 ', 'R ' union all select '仨 ', 'S ' union all
select '他 ', 'T ' union all select '屲 ', 'W ' union all
select '夕 ', 'X ' union all select '丫 ', 'Y ' union all
select '帀 ', 'Z '
select @strlen=len(@str),@re= ' '
while @strlen> 0
begin
select top 1 @re=letter+@re,@strlen=@strlen-1
from @t a where chr <=substring(@str,@strlen,1)
order by chr desc
if @@rowcount=0
select @re=substring(@str,@strlen,1)+@re,@strlen=@strlen-1
end
return(@re)
end
---查詢---
select
*
from
[pactinfo]
where
left(dbo.f_GetPy(pactname),1)='Z'
---結果---
ID pactname
----------- --------
1 正常
2 中國
3 做飯
(所影響的行數為 3 行)
Ⅳ SQL Server 如何提取漢字首字母
這個我以前寫過, 要用 C# 來寫, 然後 發布到 SQL Server 上面去。
你要是會 C# 的話, 倒可以嘗試嘗試, 否則就不必下載附件了。
那個項目還引用了 Microsoft.International.Converters.PinYinConverter 這個類庫。
你可能還要去微軟網站找來下載一下。
或者用其他的演算法, 通過漢字, 返回拼音的。
Ⅵ SQL獲取漢字首字母方法
先把漢字轉成拼音,然後取第一個字母,轉拼音可參考http://wenku..com/link?url=_EMDG0__Pt5zouVxBXciJ__,取第一個字母=left(字元串,1)