Oracle取得中文拼音首字母函数

 

CREATE
OR REPLACE FUNCTION F_TRANS_PINYIN_CAPITAL (P_NAME IN VARCHAR2) RETURN VARCHAR2 AS V_COMPARE VARCHAR2 (100) ; V_RETURN VARCHAR2 (4000) ; FUNCTION F_NLSSORT (P_WORD IN VARCHAR2) RETURN VARCHAR2 AS
BEGIN
    RETURN NLSSORT (
        P_WORD,
        'NLS_SORT=SCHINESE_PINYIN_M'
    ) ;
END ;
BEGIN
    FOR I IN 1..LENGTH (P_NAME) LOOP V_COMPARE := F_NLSSORT (SUBSTR(P_NAME, I, 1)) ;
IF V_COMPARE >= F_NLSSORT ('')
AND V_COMPARE <= F_NLSSORT ('') THEN
    V_RETURN := V_RETURN || 'a' ;
ELSIF V_COMPARE >= F_NLSSORT ('')
AND V_COMPARE <= F_NLSSORT ('簿 ') THEN
    V_RETURN := V_RETURN || 'b' ;
ELSIF V_COMPARE >= F_NLSSORT ('')
AND V_COMPARE <= F_NLSSORT ('') THEN
    V_RETURN := V_RETURN || 'c' ;
ELSIF V_COMPARE >= F_NLSSORT ('')
AND V_COMPARE <= F_NLSSORT ('') THEN
    V_RETURN := V_RETURN || 'd' ;
ELSIF V_COMPARE >= F_NLSSORT ('')
AND V_COMPARE <= F_NLSSORT ('') THEN
    V_RETURN := V_RETURN || 'e' ;
ELSIF V_COMPARE >= F_NLSSORT ('')
AND V_COMPARE <= F_NLSSORT ('') THEN
    V_RETURN := V_RETURN || 'f' ;
ELSIF V_COMPARE >= F_NLSSORT ('')
AND V_COMPARE <= F_NLSSORT ('') THEN
    V_RETURN := V_RETURN || 'g' ;
ELSIF V_COMPARE >= F_NLSSORT ('')
AND V_COMPARE <= F_NLSSORT ('') THEN
    V_RETURN := V_RETURN || 'h' ;
ELSIF V_COMPARE >= F_NLSSORT ('')
AND V_COMPARE <= F_NLSSORT ('') THEN
    V_RETURN := V_RETURN || 'j' ;
ELSIF V_COMPARE >= F_NLSSORT ('')
AND V_COMPARE <= F_NLSSORT ('') THEN
    V_RETURN := V_RETURN || 'k' ;
ELSIF V_COMPARE >= F_NLSSORT ('')
AND V_COMPARE <= F_NLSSORT ('') THEN
    V_RETURN := V_RETURN || 'l' ;
ELSIF V_COMPARE >= F_NLSSORT ('')
AND V_COMPARE <= F_NLSSORT ('') THEN
    V_RETURN := V_RETURN || 'm' ;
ELSIF V_COMPARE >= F_NLSSORT ('')
AND V_COMPARE <= F_NLSSORT ('') THEN
    V_RETURN := V_RETURN || 'n' ;
ELSIF V_COMPARE >= F_NLSSORT ('')
AND V_COMPARE <= F_NLSSORT ('') THEN
    V_RETURN := V_RETURN || 'o' ;
ELSIF V_COMPARE >= F_NLSSORT ('')
AND V_COMPARE <= F_NLSSORT ('') THEN
    V_RETURN := V_RETURN || 'p' ;
ELSIF V_COMPARE >= F_NLSSORT ('')
AND V_COMPARE <= F_NLSSORT ('') THEN
    V_RETURN := V_RETURN || 'q' ;
ELSIF V_COMPARE >= F_NLSSORT ('')
AND V_COMPARE <= F_NLSSORT ('') THEN
    V_RETURN := V_RETURN || 'r' ;
ELSIF V_COMPARE >= F_NLSSORT ('')
AND V_COMPARE <= F_NLSSORT ('') THEN
    V_RETURN := V_RETURN || 's' ;
ELSIF V_COMPARE >= F_NLSSORT ('')
AND V_COMPARE <= F_NLSSORT ('') THEN
    V_RETURN := V_RETURN || 't' ;
ELSIF V_COMPARE >= F_NLSSORT ('')
AND V_COMPARE <= F_NLSSORT ('') THEN
    V_RETURN := V_RETURN || 'w' ;
ELSIF V_COMPARE >= F_NLSSORT ('')
AND V_COMPARE <= F_NLSSORT ('') THEN
    V_RETURN := V_RETURN || 'x' ;
ELSIF V_COMPARE >= F_NLSSORT ('')
AND V_COMPARE <= F_NLSSORT ('') THEN
    V_RETURN := V_RETURN || 'y' ;
ELSIF V_COMPARE >= F_NLSSORT ('')
AND V_COMPARE <= F_NLSSORT ('') THEN
    V_RETURN := V_RETURN || 'z' ;
END
IF ;
END LOOP ; RETURN V_RETURN ;
END ;
SELECT
    F_TRANS_PINYIN_CAPITAL (
        '湖北信业建设项目管理有限公司'
    )
FROM
    dual;

posted @ 2014-03-12 15:22  wsw0515  阅读(485)  评论(0编辑  收藏  举报