Function for converting a phrase into pinyin

Source: Internet
Author: User

This function is written in SQL SERVER 2008. Due to limited time, there are still many problems to be solved: If you need a database with pinyin words (some databases only have the first pinyin words, not Suitable). Currently, this function can only convert a string of Chinese characters (without any punctuation, letters or special characters in the middle. I will improve this function if I have time. Please give me more instructions.

Create function streetii_PinYin_Convert_Class
(
@ Word nvarchar (128)
)
Returns @ temp table
(
Id int identity (1, 1 ),
Word nvarchar (128 ),
Pinyin nvarchar (255)
)
As
Begin
Declare @ pinyin nvarchar (16)
Declare @ char nvarchar (4)
Declare @ currentindex int = 1
Declare @ totalpinyin nvarchar (256) =''
Declare @ length int = len (@ word) -- check the length of the string
 
If @ word is not null
Begin
While @ currentindex <= @ Length
Begin
Set @ char = substring (@ word, @ currentindex, 1) -- split characters one by one and assign values to the variable @ char
Set @ pinyin = (select pinyin from streetii_pinyinforword where WORD = @ char) -- get the Pinyin of characters in @ char
Set @ totalpinyin = @ totalpinyin + @ Pinyin -- add to variable
Set @ currentindex = @ currentindex + 1 -- detects the next Chinese Character
End
Insert into @ temp values (@ word, @ totalpinyin)
End
Return
End

/*
Select * From streetii_pinyin_convert_class ('Welcome to Beijing ')
*/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.