oracle實現將漢字字串轉換成拼音首字母縮寫

2021-10-21 11:14:21 字數 3579 閱讀 3362

1、定義乙個函式:

create or replace function f_get_pyjm(p_name in varchar2) return varchar2 as

v_compare varchar2(100);

v_return varchar2(4000);

/*建立人:gangma2

功能描述:任意字串轉換成拼音首字元簡寫,返回拼音簡碼函 */

begin

declare

--定義乙個函式,通過nlssort來進行單個字元語言排序

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';

else

--如果不能被轉換返回原字元

v_return := v_return || upper(substr(p_name, i, 1));

end if;

end loop;

return lower(v_return);

end;

end;

2、呼叫函式,如:

php獲取漢字字串長度

int iconv strlen string str string charset ini get iconv.internal encoding 和 strlen 不同的是,iconv strlen 統計了給定的位元組序列str中出現字元數的統計,基於指定的字符集,其產生的結果不一定和字元位元組...

C 關於中文漢字字串

int main strcpy char dest,const char src dest 指向用於儲存複製內容的目標陣列。src 要複製的字串。strcpy name3 k name1 i 複製name1中的中文名字給name3 strcmp const char str1,const char ...

擷取包含漢字字串的子字串

擷取字串 本書字數 209.9萬字 中間的數字209.9 char test 10 測試 printf s d n test,int strlen test 得到結果是6也就是說每個漢字占用6個字元 然後測試目標字串的大小 char strlen tmp 40 本書字數 209.9萬字 printf...