当前位置:   article > 正文

SQL汉字转拼音函数-支持首字母、全拼

sql server拼音码函数支持多音字
  1. 作者不详
  2. --方法一sqlserver汉字转拼音首字母
  3. --调用方法 select dbo.procGetPY ('中國')
  4. Create FUNCTION dbo.procGetPY
  5. (
  6. @str NVARCHAR(4000)
  7. )
  8. /*
  9. select dbo. procGetPYFirstLetter ('中國')
  10. */
  11. RETURNS NVARCHAR(4000)
  12. --WITH ENCRYPTION
  13. AS
  14. BEGIN
  15. DECLARE @WORD NCHAR(1),@PY NVARCHAR(4000)
  16. SET @PY=''
  17. WHILE LEN(@STR)>0
  18. BEGIN
  19. SET @WORD=LEFT(@STR,1)
  20. --如果非漢字字符﹐返回原字符
  21. SET @PY=@PY+(CASE WHEN UNICODE(@WORD) BETWEEN 19968 AND 19968+20901
  22. THEN (
  23. SELECT TOP 1 PY
  24. FROM
  25. (
  26. SELECT 'A' AS PY,N'驁' AS WORD
  27. UNION ALL SELECT 'B',N'簿'
  28. UNION ALL SELECT 'C',N'錯'
  29. UNION ALL SELECT 'D',N'鵽'
  30. UNION ALL SELECT 'E',N'樲'
  31. UNION ALL SELECT 'F',N'鰒'
  32. UNION ALL SELECT 'G',N'腂'
  33. UNION ALL SELECT 'H',N'夻'
  34. UNION ALL SELECT 'J',N'攈'
  35. UNION ALL SELECT 'K',N'穒'
  36. UNION ALL SELECT 'L',N'鱳'
  37. UNION ALL SELECT 'M',N'旀'
  38. UNION ALL SELECT 'N',N'桛'
  39. UNION ALL SELECT 'O',N'漚'
  40. UNION ALL SELECT 'P',N'曝'
  41. UNION ALL SELECT 'Q',N'囕'
  42. UNION ALL SELECT 'R',N'鶸'
  43. UNION ALL SELECT 'S',N'蜶'
  44. UNION ALL SELECT 'T',N'籜'
  45. UNION ALL SELECT 'W',N'鶩'
  46. UNION ALL SELECT 'X',N'鑂'
  47. UNION ALL SELECT 'Y',N'韻'
  48. UNION ALL SELECT 'Z',N'做'
  49. ) T
  50. WHERE WORD>=@WORD COLLATE CHINESE_PRC_CS_AS_KS_WS
  51. ORDER BY PY ASC
  52. )
  53. ELSE @WORD
  54. END)
  55. SET @STR=RIGHT(@STR,LEN(@STR)-1)
  56. END
  57. RETURN @PY
  58. END
  59. Go
  60. --方法二sqlserver汉字转全拼
  61. --调用方法 select dbo. procGetPinYin ('中國')
  62. create function [dbo].procGetPinYin(@str varchar(100))
  63. returns varchar(8000)
  64. as
  65. begin
  66. declare @re varchar(8000),@crs varchar(10)
  67. declare @strlen int
  68. select @strlen=len(@str),@re=''
  69. while @strlen>0
  70. begin
  71. set @crs= substring(@str,@strlen,1)
  72. select @re=
  73. case
  74. when @crs<'吖' then @crs
  75. when @crs<='厑' then 'a'
  76. when @crs<='靉' then 'ai'
  77. when @crs<='黯' then 'an'
  78. when @crs<='醠' then 'ang'
  79. when @crs<='驁' then 'ao'
  80. when @crs<='欛' then 'ba'
  81. when @crs<='瓸' then 'bai'
  82. when @crs<='瓣' then 'ban'
  83. when @crs<='鎊' then 'bang'
  84. when @crs<='鑤' then 'bao'
  85. when @crs<='鐾' then 'bei'
  86. when @crs<='輽' then 'ben'
  87. when @crs<='鏰' then 'beng'
  88. when @crs<='鼊' then 'bi'
  89. when @crs<='變' then 'bian'
  90. when @crs<='鰾' then 'biao'
  91. when @crs<='彆' then 'bie'
  92. when @crs<='鬢' then 'bin'
  93. when @crs<='靐' then 'bing'
  94. when @crs<='蔔' then 'bo'
  95. when @crs<='簿' then 'bu'
  96. when @crs<='囃' then 'ca'
  97. when @crs<='乲' then 'cai'
  98. when @crs<='爘' then 'can'
  99. when @crs<='賶' then 'cang'
  100. when @crs<='鼜' then 'cao'
  101. when @crs<='簎' then 'ce'
  102. when @crs<='笒' then 'cen'
  103. when @crs<='乽' then 'ceng'
  104. when @crs<='詫' then 'cha'
  105. when @crs<='囆' then 'chai'
  106. when @crs<='顫' then 'chan'
  107. when @crs<='韔' then 'chang'
  108. when @crs<='觘' then 'chao'
  109. when @crs<='爡' then 'che'
  110. when @crs<='讖' then 'chen'
  111. when @crs<='秤' then 'cheng'
  112. when @crs<='鷘' then 'chi'
  113. when @crs<='銃' then 'chong'
  114. when @crs<='殠' then 'chou'
  115. when @crs<='矗' then 'chu'
  116. when @crs<='踹' then 'chuai'
  117. when @crs<='鶨' then 'chuan'
  118. when @crs<='愴' then 'chuang'
  119. when @crs<='顀' then 'chui'
  120. when @crs<='蠢' then 'chun'
  121. when @crs<='縒' then 'chuo'
  122. when @crs<='嗭' then 'ci'
  123. when @crs<='謥' then 'cong'
  124. when @crs<='輳' then 'cou'
  125. when @crs<='顣' then 'cu'
  126. when @crs<='爨' then 'cuan'
  127. when @crs<='臎' then 'cui'
  128. when @crs<='籿' then 'cun'
  129. when @crs<='錯' then 'cuo'
  130. when @crs<='橽' then 'da'
  131. when @crs<='靆' then 'dai'
  132. when @crs<='饏' then 'dan'
  133. when @crs<='闣' then 'dang'
  134. when @crs<='纛' then 'dao'
  135. when @crs<='的' then 'de'
  136. when @crs<='扽' then 'den'
  137. when @crs<='鐙' then 'deng'
  138. when @crs<='螮' then 'di'
  139. when @crs<='嗲' then 'dia'
  140. when @crs<='驔' then 'dian'
  141. when @crs<='鑃' then 'diao'
  142. when @crs<='嚸' then 'die'
  143. when @crs<='顁' then 'ding'
  144. when @crs<='銩' then 'diu'
  145. when @crs<='霘' then 'dong'
  146. when @crs<='鬭' then 'dou'
  147. when @crs<='蠹' then 'du'
  148. when @crs<='叾' then 'duan'
  149. when @crs<='譵' then 'dui'
  150. when @crs<='踲' then 'dun'
  151. when @crs<='鵽' then 'duo'
  152. when @crs<='鱷' then 'e'
  153. when @crs<='摁' then 'en'
  154. when @crs<='鞥' then 'eng'
  155. when @crs<='樲' then 'er'
  156. when @crs<='髮' then 'fa'
  157. when @crs<='瀪' then 'fan'
  158. when @crs<='放' then 'fang'
  159. when @crs<='靅' then 'fei'
  160. when @crs<='鱝' then 'fen'
  161. when @crs<='覅' then 'feng'
  162. when @crs<='梻' then 'fo'
  163. when @crs<='鴀' then 'fou'
  164. when @crs<='猤' then 'fu'
  165. when @crs<='魀' then 'ga'
  166. when @crs<='瓂' then 'gai'
  167. when @crs<='灨' then 'gan'
  168. when @crs<='戇' then 'gang'
  169. when @crs<='鋯' then 'gao'
  170. when @crs<='獦' then 'ge'
  171. when @crs<='給' then 'gei'
  172. when @crs<='搄' then 'gen'
  173. when @crs<='堩' then 'geng'
  174. when @crs<='兣' then 'gong'
  175. when @crs<='購' then 'gou'
  176. when @crs<='顧' then 'gu'
  177. when @crs<='詿' then 'gua'
  178. when @crs<='恠' then 'guai'
  179. when @crs<='鱹' then 'guan'
  180. when @crs<='撗' then 'guang'
  181. when @crs<='鱥' then 'gui'
  182. when @crs<='謴' then 'gun'
  183. when @crs<='腂' then 'guo'
  184. when @crs<='哈' then 'ha'
  185. when @crs<='饚' then 'hai'
  186. when @crs<='鶾' then 'han'
  187. when @crs<='沆' then 'hang'
  188. when @crs<='兞' then 'hao'
  189. when @crs<='靏' then 'he'
  190. when @crs<='嬒' then 'hei'
  191. when @crs<='恨' then 'hen'
  192. when @crs<='堼' then 'heng'
  193. when @crs<='鬨' then 'hong'
  194. when @crs<='鱟' then 'hou'
  195. when @crs<='鸌' then 'hu'
  196. when @crs<='蘳' then 'hua'
  197. when @crs<='蘾' then 'huai'
  198. when @crs<='鰀' then 'huan'
  199. when @crs<='鎤' then 'huang'
  200. when @crs<='顪' then 'hui'
  201. when @crs<='諢' then 'hun'
  202. when @crs<='夻' then 'huo'
  203. when @crs<='驥' then 'ji'
  204. when @crs<='嗧' then 'jia'
  205. when @crs<='鑳' then 'jian'
  206. when @crs<='謽' then 'jiang'
  207. when @crs<='釂' then 'jiao'
  208. when @crs<='繲' then 'jie'
  209. when @crs<='齽' then 'jin'
  210. when @crs<='竸' then 'jing'
  211. when @crs<='蘔' then 'jiong'
  212. when @crs<='欍' then 'jiu'
  213. when @crs<='爠' then 'ju'
  214. when @crs<='羂' then 'juan'
  215. when @crs<='钁' then 'jue'
  216. when @crs<='攈' then 'jun'
  217. when @crs<='鉲' then 'ka'
  218. when @crs<='乫' then 'kai'
  219. when @crs<='矙' then 'kan'
  220. when @crs<='閌' then 'kang'
  221. when @crs<='鯌' then 'kao'
  222. when @crs<='騍' then 'ke'
  223. when @crs<='褃' then 'ken'
  224. when @crs<='鏗' then 'keng'
  225. when @crs<='廤' then 'kong'
  226. when @crs<='鷇' then 'kou'
  227. when @crs<='嚳' then 'ku'
  228. when @crs<='骻' then 'kua'
  229. when @crs<='鱠' then 'kuai'
  230. when @crs<='窾' then 'kuan'
  231. when @crs<='鑛' then 'kuang'
  232. when @crs<='鑎' then 'kui'
  233. when @crs<='睏' then 'kun'
  234. when @crs<='穒' then 'kuo'
  235. when @crs<='鞡' then 'la'
  236. when @crs<='籟' then 'lai'
  237. when @crs<='糷' then 'lan'
  238. when @crs<='唥' then 'lang'
  239. when @crs<='軂' then 'lao'
  240. when @crs<='餎' then 'le'
  241. when @crs<='脷' then 'lei'
  242. when @crs<='睖' then 'leng'
  243. when @crs<='瓈' then 'li'
  244. when @crs<='倆' then 'lia'
  245. when @crs<='纞' then 'lian'
  246. when @crs<='鍄' then 'liang'
  247. when @crs<='瞭' then 'liao'
  248. when @crs<='鱲' then 'lie'
  249. when @crs<='轥' then 'lin'
  250. when @crs<='炩' then 'ling'
  251. when @crs<='咯' then 'liu'
  252. when @crs<='贚' then 'long'
  253. when @crs<='鏤' then 'lou'
  254. when @crs<='氇' then 'lu'
  255. when @crs<='鑢' then 'lv'
  256. when @crs<='亂' then 'luan'
  257. when @crs<='擽' then 'lue'
  258. when @crs<='論' then 'lun'
  259. when @crs<='鱳' then 'luo'
  260. when @crs<='嘛' then 'ma'
  261. when @crs<='霢' then 'mai'
  262. when @crs<='蘰' then 'man'
  263. when @crs<='蠎' then 'mang'
  264. when @crs<='唜' then 'mao'
  265. when @crs<='癦' then 'me'
  266. when @crs<='嚜' then 'mei'
  267. when @crs<='們' then 'men'
  268. when @crs<='霥' then 'meng'
  269. when @crs<='羃' then 'mi'
  270. when @crs<='麵' then 'mian'
  271. when @crs<='廟' then 'miao'
  272. when @crs<='鱴' then 'mie'
  273. when @crs<='鰵' then 'min'
  274. when @crs<='詺' then 'ming'
  275. when @crs<='謬' then 'miu'
  276. when @crs<='耱' then 'mo'
  277. when @crs<='麰' then 'mou'
  278. when @crs<='旀' then 'mu'
  279. when @crs<='魶' then 'na'
  280. when @crs<='錼' then 'nai'
  281. when @crs<='婻' then 'nan'
  282. when @crs<='齉' then 'nang'
  283. when @crs<='臑' then 'nao'
  284. when @crs<='呢' then 'ne'
  285. when @crs<='焾' then 'nei'
  286. when @crs<='嫩' then 'nen'
  287. when @crs<='能' then 'neng'
  288. when @crs<='嬺' then 'ni'
  289. when @crs<='艌' then 'nian'
  290. when @crs<='釀' then 'niang'
  291. when @crs<='脲' then 'niao'
  292. when @crs<='钀' then 'nie'
  293. when @crs<='拰' then 'nin'
  294. when @crs<='濘' then 'ning'
  295. when @crs<='靵' then 'niu'
  296. when @crs<='齈' then 'nong'
  297. when @crs<='譳' then 'nou'
  298. when @crs<='搙' then 'nu'
  299. when @crs<='衄' then 'nv'
  300. when @crs<='瘧' then 'nue'
  301. when @crs<='燶' then 'nuan'
  302. when @crs<='桛' then 'nuo'
  303. when @crs<='鞰' then 'o'
  304. when @crs<='漚' then 'ou'
  305. when @crs<='袙' then 'pa'
  306. when @crs<='磗' then 'pai'
  307. when @crs<='鑻' then 'pan'
  308. when @crs<='胖' then 'pang'
  309. when @crs<='礮' then 'pao'
  310. when @crs<='轡' then 'pei'
  311. when @crs<='喯' then 'pen'
  312. when @crs<='喸' then 'peng'
  313. when @crs<='鸊' then 'pi'
  314. when @crs<='騙' then 'pian'
  315. when @crs<='慓' then 'piao'
  316. when @crs<='嫳' then 'pie'
  317. when @crs<='聘' then 'pin'
  318. when @crs<='蘋' then 'ping'
  319. when @crs<='魄' then 'po'
  320. when @crs<='哛' then 'pou'
  321. when @crs<='曝' then 'pu'
  322. when @crs<='蟿' then 'qi'
  323. when @crs<='髂' then 'qia'
  324. when @crs<='縴' then 'qian'
  325. when @crs<='瓩' then 'qiang'
  326. when @crs<='躈' then 'qiao'
  327. when @crs<='籡' then 'qie'
  328. when @crs<='藽' then 'qin'
  329. when @crs<='櫦' then 'qing'
  330. when @crs<='瓗' then 'qiong'
  331. when @crs<='糗' then 'qiu'
  332. when @crs<='覻' then 'qu'
  333. when @crs<='勸' then 'quan'
  334. when @crs<='礭' then 'que'
  335. when @crs<='囕' then 'qun'
  336. when @crs<='橪' then 'ran'
  337. when @crs<='讓' then 'rang'
  338. when @crs<='繞' then 'rao'
  339. when @crs<='熱' then 're'
  340. when @crs<='餁' then 'ren'
  341. when @crs<='陾' then 'reng'
  342. when @crs<='馹' then 'ri'
  343. when @crs<='穃' then 'rong'
  344. when @crs<='嶿' then 'rou'
  345. when @crs<='擩' then 'ru'
  346. when @crs<='礝' then 'ruan'
  347. when @crs<='壡' then 'rui'
  348. when @crs<='橍' then 'run'
  349. when @crs<='鶸' then 'ruo'
  350. when @crs<='栍' then 'sa'
  351. when @crs<='虄' then 'sai'
  352. when @crs<='閐' then 'san'
  353. when @crs<='喪' then 'sang'
  354. when @crs<='髞' then 'sao'
  355. when @crs<='飋' then 'se'
  356. when @crs<='篸' then 'sen'
  357. when @crs<='縇' then 'seng'
  358. when @crs<='霎' then 'sha'
  359. when @crs<='曬' then 'shai'
  360. when @crs<='鱔' then 'shan'
  361. when @crs<='緔' then 'shang'
  362. when @crs<='潲' then 'shao'
  363. when @crs<='欇' then 'she'
  364. when @crs<='瘮' then 'shen'
  365. when @crs<='賸' then 'sheng'
  366. when @crs<='瓧' then 'shi'
  367. when @crs<='鏉' then 'shou'
  368. when @crs<='虪' then 'shu'
  369. when @crs<='誜' then 'shua'
  370. when @crs<='卛' then 'shuai'
  371. when @crs<='腨' then 'shuan'
  372. when @crs<='灀' then 'shuang'
  373. when @crs<='睡' then 'shui'
  374. when @crs<='鬊' then 'shun'
  375. when @crs<='鑠' then 'shuo'
  376. when @crs<='乺' then 'si'
  377. when @crs<='鎹' then 'song'
  378. when @crs<='瘶' then 'sou'
  379. when @crs<='鷫' then 'su'
  380. when @crs<='算' then 'suan'
  381. when @crs<='鐩' then 'sui'
  382. when @crs<='潠' then 'sun'
  383. when @crs<='蜶' then 'suo'
  384. when @crs<='襨' then 'ta'
  385. when @crs<='燤' then 'tai'
  386. when @crs<='賧' then 'tan'
  387. when @crs<='燙' then 'tang'
  388. when @crs<='畓' then 'tao'
  389. when @crs<='蟘' then 'te'
  390. when @crs<='朰' then 'teng'
  391. when @crs<='趯' then 'ti'
  392. when @crs<='舚' then 'tian'
  393. when @crs<='糶' then 'tiao'
  394. when @crs<='餮' then 'tie'
  395. when @crs<='乭' then 'ting'
  396. when @crs<='憅' then 'tong'
  397. when @crs<='透' then 'tou'
  398. when @crs<='鵵' then 'tu'
  399. when @crs<='褖' then 'tuan'
  400. when @crs<='駾' then 'tui'
  401. when @crs<='坉' then 'tun'
  402. when @crs<='籜' then 'tuo'
  403. when @crs<='韤' then 'wa'
  404. when @crs<='顡' then 'wai'
  405. when @crs<='贎' then 'wan'
  406. when @crs<='朢' then 'wang'
  407. when @crs<='躛' then 'wei'
  408. when @crs<='璺' then 'wen'
  409. when @crs<='齆' then 'weng'
  410. when @crs<='齷' then 'wo'
  411. when @crs<='鶩' then 'wu'
  412. when @crs<='衋' then 'xi'
  413. when @crs<='鏬' then 'xia'
  414. when @crs<='鼸' then 'xian'
  415. when @crs<='鱌' then 'xiang'
  416. when @crs<='斆' then 'xiao'
  417. when @crs<='躞' then 'xie'
  418. when @crs<='釁' then 'xin'
  419. when @crs<='臖' then 'xing'
  420. when @crs<='敻' then 'xiong'
  421. when @crs<='齅' then 'xiu'
  422. when @crs<='蓿' then 'xu'
  423. when @crs<='贙' then 'xuan'
  424. when @crs<='瀥' then 'xue'
  425. when @crs<='鑂' then 'xun'
  426. when @crs<='齾' then 'ya'
  427. when @crs<='灩' then 'yan'
  428. when @crs<='樣' then 'yang'
  429. when @crs<='鑰' then 'yao'
  430. when @crs<='岃' then 'ye'
  431. when @crs<='齸' then 'yi'
  432. when @crs<='檼' then 'yin'
  433. when @crs<='譍' then 'ying'
  434. when @crs<='喲' then 'yo'
  435. when @crs<='醟' then 'yong'
  436. when @crs<='鼬' then 'you'
  437. when @crs<='爩' then 'yu'
  438. when @crs<='願' then 'yuan'
  439. when @crs<='鸙' then 'yue'
  440. when @crs<='韻' then 'yun'
  441. when @crs<='雥' then 'za'
  442. when @crs<='縡' then 'zai'
  443. when @crs<='饡' then 'zan'
  444. when @crs<='臟' then 'zang'
  445. when @crs<='竈' then 'zao'
  446. when @crs<='稄' then 'ze'
  447. when @crs<='鱡' then 'zei'
  448. when @crs<='囎' then 'zen'
  449. when @crs<='贈' then 'zeng'
  450. when @crs<='醡' then 'zha'
  451. when @crs<='瘵' then 'zhai'
  452. when @crs<='驏' then 'zhan'
  453. when @crs<='瞕' then 'zhang'
  454. when @crs<='羄' then 'zhao'
  455. when @crs<='鷓' then 'zhe'
  456. when @crs<='黮' then 'zhen'
  457. when @crs<='證' then 'zheng'
  458. when @crs<='豒' then 'zhi'
  459. when @crs<='諥' then 'zhong'
  460. when @crs<='驟' then 'zhou'
  461. when @crs<='鑄' then 'zhu'
  462. when @crs<='爪' then 'zhua'
  463. when @crs<='跩' then 'zhuai'
  464. when @crs<='籑' then 'zhuan'
  465. when @crs<='戅' then 'zhuang'
  466. when @crs<='鑆' then 'zhui'
  467. when @crs<='稕' then 'zhun'
  468. when @crs<='籱' then 'zhuo'
  469. when @crs<='漬' then 'zi'
  470. when @crs<='縱' then 'zong'
  471. when @crs<='媰' then 'zou'
  472. when @crs<='謯' then 'zu'
  473. when @crs<='攥' then 'zuan'
  474. when @crs<='欈' then 'zui'
  475. when @crs<='銌' then 'zun'
  476. when @crs<='咗' then 'zuo'
  477. --else @crs end+' '+@re,@strlen=@strlen-1
  478. --去掉拼音之间的间隔
  479. else @crs end+''+@re,@strlen=@strlen-1
  480. end
  481. return(@re)
  482. end
  483. go



转载于:https://my.oschina.net/ind/blog/191659

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/399353
推荐阅读
相关标签
  

闽ICP备14008679号