1. 程式人生 > >sqlserver取漢字的首字母的函式

sqlserver取漢字的首字母的函式

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 @[email protected]+(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>

[email protected] 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

相關推薦

sqlserver漢字字母函式

Create  function fun_getPY  (     @str nvarchar(4000)  ) returns nvarchar(4000) as begin   declare @word nchar(1),@PY nvarchar(4000)   s

獲取漢字字母

per ant 英文 ret 一個 spel span def ati /// <summary> /// 得到一個漢字的拼音第一個字母,如果是一個英文字母則直接返回大寫字母 /// </summary>

JS實現獲取漢字字母拼音、全拼音及混拼音的方法

pla 輸入 files sta add 參考 x11 lba odi 本文實例講述了JS實現獲取漢字首字母拼音、全拼音及混拼音的方法。分享給大家供大家參考,具體如下: 這裏需要用到一個js獲取漢字拼音的插件,可點擊此處本站下載。 運行效果如下: 完整示例代碼: ?

漢字字母拼音排序-Python

安裝pypinyin,目的是將中文轉換成拼音 pip install pypinyin 利用sort()函式進行排序 from pypinyin import lazy_pinyin chinese_list=[u'中國人', u'啊', u'

javascirpt 獲取漢字字母

原文連結:http://www.cnblogs.com/kinnjee/p/4160060.html var PinYin = { "a": "\u554a\u963f\u9515", "ai": "\u57c3\u6328\u54ce\u5509\u54c0\u7691

mysql獲取漢字字母函數

arch cef character get gbk then val 函數 mysql DELIMITER ;;CREATE FUNCTION `GET_FIRST_PINYIN_CHAR`(PARAM VARCHAR(255)) RETURNS VARCHAR(2) C

mysql 根據漢字字母排序

  1:如果資料庫表字段的字元編碼是latin1_swedish_ci select * from tablename order by birary(name) asc ;   2:如果資料庫表字段的字元編碼是utf8_general_ci(常用) sele

字串字母變更為大寫字母,其餘小寫字母(兩種方法 substring()與charAt())。

package demo_取部分字串將其轉換大小寫; public class toUpperCaseAndtoLowerCase { public static void main(String[] args) { toConvert("sdfdsgre")

根據漢字字母排序並進行分組

需  求: 頁面有一個下拉選項框(選擇汽車品牌),由於品牌比較多,所以需要通過首字母就能快捷選擇,也就是說:點選字母 “B”後,把汽車品牌首拼音字母為 “B” 的顯示出來。汽車品牌資料從資料庫表裡面取。 分  析: 這裡分兩種情況,第一種:表裡面有汽車品牌名稱首字母欄位

通訊錄之按漢字字母排序-java

最近開發手機端OA系統通訊錄時遇到了用漢字首字母排序的問題,各種谷歌後發現了一個輪子pinyin4J,這個輪子是可以將漢字轉換成字母拼音,個人覺得很好用,完美的解決了排序的問題,分享一下。 原部落格地址 一.工具介紹 pinyin4j是一個支援將簡

Android 漢字字母排序

需要用到的方法: 用到jar包: pinYin4j.jar /** * 漢字轉換位漢語拼音首字母,英文字元不變 * @param chines 漢字 * @re

oracle 提取中文字串拼音字母函式,拼音簡碼提取函式

從別的資料庫裡拿到的獲取拼音簡碼的函式,覺得挺有意思的,具體的思路就是,通過oracle的NLSSORT函式對漢字按照拼音排序,然後根據漢字的區間返回對應的首字母。具體實現效果和程式碼如下。 希望能幫助到你 /* 獲取拼音簡碼函式 */ CREATE OR REPL

PHP獲取漢字字母函數

pri rto upper amp icon php light 獲取 {0} function getFirstCharter($str) { if (empty($str)) { return ‘‘; } $fchar

java 優先順序以特殊字元、數字、英文、漢字(且漢字部分以漢字字母)順序排序

1,當我使用如下程式碼對其中的list進行排序時: 優先順序以特殊字元、數字、英文、漢字(且漢字部分以漢字首字母)順序排序 @Test public void sortList(){ List<String>list=Lists.newA

asp.net漢字轉拼音和獲取漢字字母的程式碼

using System; using System.Data; using System.Configuration; using System.Text; /// <summary> /// Summary description for ConvertHzToPz

mysql根據漢字字母排序的方法

實現mysql中根據漢字首字母排序的sql語句:   程式碼示例:select areaname from area order by convert(areaname using gbk) collate gbk_chinese_ci asc 說明: areaname

根據中文拼音字母排序、取得中文拼音字母函式 oracle 排序

根據中文拼音首字母排序、取得中文拼音首字母函式 介紹根據中文的首字母、筆畫、部首排序函式【NLSSORT】: 1)、首字母 SELECT * FROM T_TABLE ORDER BY NLSSORT(NAME, 'NLS_SORT=SCHINESE_PINYIN_M'

漢字拼音字母的方法

nts cti res character con andro 字節 ext creat 近期在做一個按拼音首字母排序的ListView須要取漢字拼音首字母,Deomo下載地址:http://download.csdn.net/detail/u014649598/8

oracle漢字轉拼音(獲得全拼/拼音字母/拼音截等)

sub 截取 需要 sel 內容 zip bsp .com 整理 oracle漢字轉拼音(獲得全拼/拼音首字母/拼音截取等) 效果如下: Oracle 字符集 GBK 沒有問題 , UTF -8 需要修改一下Sql代碼 --oracle漢字轉拼音 PACKAGE --1

php---------漢字的第一個字的字母

asc str 字母 -- first sse per amp pos 開發中用到的方法,取出第一個漢字的首字母; /** * 取漢字的第一個字的首字母 * @param string $str * @return string|null */ function