The method I provide has the following characteristics:
1. Code simplification, simple to use, as long as the basic SQL statement will be the line
2. No need to build MySQL functions and other complex things
3. The most complete Chinese character library, can query 20,902 characters
Here's how:
1. Establishment of pinyin first letter data sheet
SQL code: (preferably plus primary key and index)
- DROP TABLE IF EXISTS ' Pinyin ';
- CREATE TABLE ' Pinyin ' (
- ' PY ' varchar (1),
- ' HZ1 ' varchar (1),
- ' HZ2 ' varchar (1)
- ) ;
- INSERT into ' pinyin ' (' PY ', ' HZ1 ', ' HZ2 ') VALUES
- (' A ',' acridine ',' 驁 '),
- (' B ',' eight ',' book '),
- (' C ',' cha ',' wrong '),
- (' D ',' Otah ',' 鵽 '),
- (' E ',' Ehegan ',' 樲 '),
- (' F ',' fa ','鰒 '),
- (' G ',' 猤 ',' hiker '),
- (' H ',' 妎 ',' inceѕt '),
- (' J ',' no ',' 攈 '),
- (' K ',' ka ',' 穒 '),
- (' L ','garbage ',' 鱳 '),
- (' M ',' 嘸 ',' temperature '),
- (' N ',' cabal ',' 桛 '),
- (' O ',' Oh ',' 漚 '),
- (' P ',' 妑 ',' exposure '),
- (' Q ',' seven ',' 囕 '),
- (' R ',' 呥 ',' 鶸 '),
- (' S ',' sa',' 蜶 '),
- (' T ',' he ',' 籜 '),
- (' W ',' 屲 ',' clamoring '),
- (' X ',' XI ',' 鑂 '),
- (' Y ',' ya ',' Wan Leng '),
- (' Z ',' as','n ');
after execution, check to see if the data records in the added table have "? The question mark, if any, indicates a problem with the database encoding.
2, query the database table in the first character phonetic Alphabet
SELECT ' Pinyin '. py, ' corresponding table '. *
From ' corresponding table ', ' Pinyin '
WHERE ' Kanji title ' >= ' HZ1 '
and ' Kanji title ' <= ' HZ2 ';
You can also directly query the first character of Chinese characters Phonetic Alphabet
SELECT ' pinyin '. Py
From ' Pinyin '
WHERE ' kanji ' >= ' hz1 '
and ' kanji ' <= ' hz2 ';
The query result is "H"
* * * * * Note
This method is only applicable to GBK encoding, the other encoding needs to be converted to GBK first, can be used with convert (words using GBK)
you can also use functions to handle
CREATEFUNCTIONfirstpy (wordsvarchar (255))RETURNSMediumtext
BEGIN
Declarefpychar (1);
DeclarePCchar (1);
Declareccchar (4);
Set@fpy = UPPER (Left (words,1));
Set@pc = (CONVERT (@fpyUSINGGBK));
Set@cc = Hex (@pc);
if@cc>="8140" and@cc<= "FEA0" Then
begin
Selectpy into@fpy fromPinyinwhereHz2>[email protected]and Hz1<[email protected];
end;
Endif;
Return@fpy;
END