范文健康探索娱乐情感热点
投稿投诉
热点动态
科技财经
情感日志
励志美文
娱乐时尚
游戏搞笑
探索旅游
历史星座
健康养生
美丽育儿
范文作文
教案论文

MySQL实现汉字转拼音,赶快一起学起来

  今天接到一个新的业务需求,客户需要将指定的中文汉字转换成拼音(含:简拼、首全拼、尾全拼)。 1. 创建基础数据表-- ----------------------------
  -- Table structure for bst_wbjq
  -- ----------------------------
  DROP TABLE IF EXISTS `bst_wbjq`;
  CREATE TABLE `bst_wbjq` (
  `CHARACTOR` varchar(200) NOT NULL,
  `WORD` varchar(100) NOT NULL,
  `CODE` varchar(100) DEFAULT NULL,
  `STROKE` varchar(200) DEFAULT NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  -- ----------------------------
  -- Table structure for tbl_pinyin
  -- ----------------------------
  DROP TABLE IF EXISTS `tbl_pinyin`;
  CREATE TABLE `tbl_pinyin` (
  `SN` bigint(20) NOT NULL,
  `WORD` varchar(200) NOT NULL,
  `PY` varchar(200) NOT NULL,
  `PYLEVEL` int(11) DEFAULT NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 2. 插入基础数据记录-- ----------------------------
  -- Records of bst_wbjq
  -- ----------------------------
  truncate table bst_wbjq;
  INSERT INTO `bst_wbjq` VALUES ("禅", "C", "P", "^K");
  INSERT INTO `bst_wbjq` VALUES ("讶", "Y", "Y", "2T");
  INSERT INTO `bst_wbjq` VALUES ("焉", "Y", "G", "Pa");
  INSERT INTO `bst_wbjq` VALUES ("阉", "Y", "U", "V2");
  INSERT INTO `bst_wbjq` VALUES ("烟", "Y", "O", "Ng");
  INSERT INTO `bst_wbjq` VALUES ("淹", "Y", "I", "V^");
  INSERT INTO `bst_wbjq` VALUES ("圊", "Q", "L", "Rz");
  INSERT INTO `bst_wbjq` VALUES ("圉", "Y", "L", "S?");
  INSERT INTO `bst_wbjq` VALUES ("帔", "P", "M", ";~");
  .... ....
  commit;
  -- ----------------------------
  -- Records of tbl_pinyin
  -- ----------------------------
  truncate table tbl_pinyin;
  INSERT INTO `tbl_pinyin` VALUES ("33641", "胫", "jing4", "0");
  INSERT INTO `tbl_pinyin` VALUES ("30749", "箅", "bi4", "0");
  INSERT INTO `tbl_pinyin` VALUES ("30750", "箢", "yuan1", "0");
  INSERT INTO `tbl_pinyin` VALUES ("30751", "篁", "huang2", "0");
  INSERT INTO `tbl_pinyin` VALUES ("30752", "篦", "bi4", "0");
  INSERT INTO `tbl_pinyin` VALUES ("30753", "篾", "mie4", "0");
  INSERT INTO `tbl_pinyin` VALUES ("30754", "簋", "gui3", "0");
  INSERT INTO `tbl_pinyin` VALUES ("30755", "簪", "zan1", "0");
  INSERT INTO `tbl_pinyin` VALUES ("30756", "籀", "zhou4", "0");
  INSERT INTO `tbl_pinyin` VALUES ("30757", "舄", "xi4", "0");
  INSERT INTO `tbl_pinyin` VALUES ("30758", "舢", "shan1", "0");
  INSERT INTO `tbl_pinyin` VALUES ("30759", "舨", "ban3", "0");
  .... ....
  commit;3. 创建汉字转拼音函数(存储过程、函数)3.1. 创建存储过程:PRC_GET_PYM-- ----------------------------
  -- procedure structure for PRC_GET_PYM
  -- ----------------------------
  delimiter $
  drop procedure if exists PRC_GET_PYM;
  $
  create procedure PRC_GET_PYM(IN V_NAME varchar(256),OUT V_PYM varchar(256))
  begin
  declare i int default 1;
  declare j int default 0;
  declare V_PINYIN_TEMP VARCHAR(70);
  declare V_NAME_TEMP varchar(200);
  declare V_NAME_SIN varchar(10);
  declare V_PINYIN_SIN varchar(10);
  declare v_counter1 int(8);
  #替换各种特殊符号
  select replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(
  replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(
  replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(
  replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(
  replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(
  replace(replace(replace(replace(replace(replace(replace(replace(V_NAME,
  "A","A"),"B","B"),"C","C"),"D","D"),"E","E"),"F","F"),"G","G"),"H","H"),
  "I","I"),"J","J"),"K","K"),"L","L"),"M","M"),"N","N"),"O","O"),"P","P"),
  "Q","Q"),"R","R"),"S","S"),"T","T"),"U","U"),"V","V"),"W","W"),"X","X"),
  "Y","Y"),"Z","Z"),"+",""),"-",""),"*",""),"/",""),
  "[",""),"]",""),"{",""),"}",""),"(",""),")",""),
  "<",""),">",""),"《",""),"》",""),"(",""),")",""),""",""),
  """,""),""",""),".",""),"。",""),"-",""),"-",""),"/",""),
  "/",""),"  ","")," ",""),"1","一"),"2","二"),"3","三"),
  "4","四"),"5","五"),"6","六"),"7","七"),"8","八"),"9","九"),"0","零") R3
  into V_NAME_TEMP
  from dual;
  #循环获得字符串拼音码
  myloop:loop
  if V_NAME is null then
  leave myloop;
  end if;
  select substr(V_NAME_TEMP, i, 1) into V_NAME_SIN from dual;
  set i=i+1;
  if V_NAME_SIN <> " " then
  select count(*)
  into v_counter1
  from bst_wbjq
  where bst_wbjq.charactor=v_name_sin;
  if v_counter1 > 0 then
  select WORD
  into V_PINYIN_SIN
  from bst_wbjq
  where bst_wbjq.CHARACTOR=V_NAME_SIN
  limit 1;
  select concat_ws("",V_PINYIN_TEMP,V_PINYIN_SIN)
  into V_PINYIN_TEMP
  from dual;
  end if;
  end if;
  select char_length(V_NAME) into j from dual;
  if i > j then
  leave myloop;
  end if;
  end loop;
  #截取32位长度字符
  if char_length(V_PINYIN_TEMP) > 32 then
  select substr(V_PINYIN_TEMP, 1, 32) into V_PYM from dual;
  else
  select V_PINYIN_TEMP into V_PYM from dual;
  end if;
  end;
  $
  delimiter ;3.2. 创建存储过程:SP_PINYIN-- ----------------------------
  -- procedure structure for SP_PINYIN
  -- ----------------------------
  delimiter $
  drop procedure if exists SP_PINYIN;
  $
  create procedure SP_PINYIN(IN hanzi varchar(256),OUT pinyin varchar(256))
  begin
  declare aword varchar(200);
  declare aresult varchar(200);
  declare temp1 varchar(20);
  declare len int default 0;
  declare point int default 1;
  declare charword varchar(20);
  declare charlen int default 1;
  #定义游标标志变量
  declare done int default false;
  #定义游标
  declare cur_pinyin cursor for
  select PY from TBL_PINYIN
  where word=substr(aword, point, charlen);
  #指定游标循环结束时的返回值
  declare continue HANDLER for not found set done=true;
  select ltrim(rtrim(hanzi)) into aword from dual;
  select char_length(aword) into len from dual;
  #<>
  while point <= len do
  select "" into temp1 from dual;
  select substr(aword, point, 1) into charword from dual;
  if (charword is not null and charword != " ") then
  select concat_ws(" ",aresult,charword) into aresult from dual;
  else
  select 2 into charlen from dual;
  end if;
  #打开游标
  open cur_pinyin;
  #开始循环处理游标里的数据
  read_loop:loop
  #获得游标当前指向的一条数据
  fetch cur_pinyin into temp1;
  #判断游标的循环是否结束
  if done then
  leave read_loop;
  end if;
  end loop; #结束游标循环
  #关闭游标
  close cur_pinyin;
  if (point = 1) then
  set aresult = temp1;
  else
  select concat_ws(" ",aresult,temp1) into aresult from dual;
  end if;
  select point+charlen into point from dual;
  end while;
  #输出结果
  select aresult into pinyin from dual;
  end;
  $
  delimiter ;3.3. 创建函数:to_pinyin-- ----------------------------
  -- function structure for to_pinyin
  -- ----------------------------
  delimiter $
  drop function if exists to_pinyin;
  $
  create function to_pinyin(v_hanzi varchar(256),v_type int)
  returns varchar(256)
  begin
  declare strTemp VARCHAR(200);
  declare strResult VARCHAR(200);
  declare strHanzi VARCHAR(200);
  declare strTemp1 VARCHAR(200);
  declare v_subb VARCHAR(100);
  declare V_NAME_TEMP VARCHAR(200);
  declare v_pinyin VARCHAR(200);
  #替换各种特殊符号
  select replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(
  replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(
  replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(
  replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(
  replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(
  replace(replace(replace(replace(replace(replace(replace(replace(v_hanzi,
  "A","A"),"B","B"),"C","C"),"D","D"),"E","E"),"F","F"),"G","G"),"H","H"),
  "I","I"),"J","J"),"K","K"),"L","L"),"M","M"),"N","N"),"O","O"),"P","P"),
  "Q","Q"),"R","R"),"S","S"),"T","T"),"U","U"),"V","V"),"W","W"),"X","X"),
  "Y","Y"),"Z","Z"),"+",""),"-",""),"*",""),"/",""),
  "[",""),"]",""),"{",""),"}",""),"(",""),")",""),
  "<",""),">",""),"《",""),"》",""),"(",""),")",""),""",""),
  """,""),""",""),".",""),"。",""),"-",""),"-",""),"/",""),
  "/",""),"  ","")," ",""),"1","一"),"2","二"),"3","三"),
  "4","四"),"5","五"),"6","六"),"7","七"),"8","八"),"9","九"),"0","零") R3
  into V_NAME_TEMP
  from dual;
  if v_type = "1" then #简拼
  set @V_NAME_TEMP=V_NAME_TEMP;
  set @strResult=null;
  call Prc_Get_Pym(@V_NAME_TEMP, @strResult);
  elseif v_type = "2" then #尾全拼
  #判断结尾字符是否是中文
  select ltrim(rtrim(substr(V_NAME_TEMP, char_length(V_NAME_TEMP), char_length(V_NAME_TEMP))))
  into v_subb
  from dual;
  if v_subb is null then #如果不是中文则直接生成开口码
  set @V_NAME_TEMP=V_NAME_TEMP;
  set @strResult=null;
  call Prc_Get_Pym(@V_NAME_TEMP, @strResult);
  else
  select substr(V_NAME_TEMP, 1, char_length(V_NAME_TEMP)-1) into strHanzi from dual;
  set @strHanzi=strHanzi;
  set @strTemp1=null;
  call Prc_Get_Pym(@strHanzi, @strTemp1);
  select substr(V_NAME_TEMP, char_length(V_NAME_TEMP), char_length(V_NAME_TEMP)) into strHanzi from dual;
  set @strHanzi=strHanzi;
  set @strTemp=null;
  call Sp_Pinyin(@strHanzi, @strTemp);
  select substr(@strTemp, 1, char_length(@strTemp) - 1) into @strResult from dual;
  select concat_ws("",@strTemp1,@strResult) into @strResult from dual;
  end if;
  elseif v_type = "3" then #首全拼
  #判断开头字符是否是中文
  select ltrim(rtrim(substr(V_NAME_TEMP, 1, 1))) into v_subb from dual;
  if v_subb is null then #如果不是中文则直接生成开口码
  set @V_NAME_TEMP=V_NAME_TEMP;
  set @strResult=null;
  call Prc_Get_Pym(@V_NAME_TEMP, @strResult);
  else
  select substr(V_NAME_TEMP, 2, char_length(V_NAME_TEMP)) into strHanzi from dual;
  set @strHanzi=strHanzi;
  set @strResult=null;
  call Prc_Get_Pym(@strHanzi, @strResult);
  select substr(V_NAME_TEMP, 1, 1) into strHanzi from dual;
  set @strHanzi=strHanzi;
  set @strTemp=null;
  call Sp_Pinyin(@strHanzi, @strTemp);
  select concat_ws("",substr(@strTemp, 1, char_length(@strTemp) - 1),@strResult) into @strResult from dual;
  end if;
  end if;
  set v_pinyin=UPPER(@strResult);
  return v_pinyin;
  end;
  $
  delimiter ;4. 使用方法/案例

实现花式躺平,一个冰箱就够了!陪你玩,帮你做事很多人上一天班特别的累,回到家里就想好好的休息休息,躺平一下。然而现实生活是,下班回家以后自己要洗衣服做饭还要打扫卫生。那真是上班累,下班更累!然而就有人问了,有没有正确的懒人躺平斯大林的女儿多任性?三个孩子有三个父亲,叛逃美国却孤老终身领袖的千金,大国的公主,在我们普通人眼里,应该是集美貌和万千宠爱于一生,与白马王子自由自在地过着童话般浪漫幸福的生活。然而,被斯大林视为掌上明珠的女儿,苏联的公主斯维特兰娜,却没有(国际)走进古埃及法老图坦卡蒙墓当日,埃及举办各种活动庆祝图坦卡蒙墓发现100周年。图坦卡蒙是古埃及新王国时期第十八王朝法老,9岁登基,19岁去世,在位时间约为公元前1332年至公元前1323年。其陵墓位于埃及南四部门进一步做好最低生活保障等社会救助兜底保障工作11月8日,民政部中央农村工作领导小组办公室财政部国家乡村振兴局发布关于进一步做好最低生活保障等社会救助兜底保障工作的通知。全文如下为贯彻落实国务院常务会议精神,及时将符合条件的困特斯拉ModelXPlaid800万内性价比最高SUV?6个座椅,2。6秒破百ModelX是特斯拉第二款量产的车型,在当时带鸥翼门0100kmh加速3。1秒(P100D车型)的它就已经堪称地表最强SUV了。而在去年,特斯拉还为我们带来了ModelXPlaid龙溪安装docker服务1操作系统的安装就不再重复了,我使用了最小安装,所以安装后最好安装一个nettools用来使用ifconfig命令yuminstallynettools直接使用centOS的命令进陆奇年度分享前沿科技创新创业趋势分析(2022)2022年10月29日,奇绩创坛在北京中关村举办了2022年的年度分享活动前沿科技创新创业趋势分析(2022),奇绩创坛创始人兼CEO陆奇博士与创业者分享奇绩创坛这一年来看到的前沿全网最详细笔记张益唐北大讲解火热出炉!本质上已证明零点猜想编辑编辑部新智元导读关于零点猜想问题,大海里的针我没捞到,但海底地貌我探得差不多了。一支马克笔,一张小白板。刚刚,张益唐教授现身北大,在B站的直播平台上,给广大网友上了一堂大师级数为数字中国持续创新,华为提出共同筑牢中国数字基础设施四大举措中国,深圳,2022年11月8日今日,在华为全联接大会2022上,华为常务董事ICT基础设施业务管理委员会主任汪涛发表持续创新,共同筑牢中国数字基础设施主题演讲,提出打造领先的网络特斯拉关闭中国首家门店,转战郊区能否成造车新势力降低成本新趋势?特斯拉在中国开设的第一家门店关闭了。界面新闻致电这家位于侨福芳草地的特斯拉体验中心,电话被转接到附近的来福士门店。特斯拉销售称,侨福芳草地门店已在上上周撤店,原因是租约到期没有续签为什么钱越来越难赚了?时代的选择,周期已到拐点在经济的上行期,时代会奖励那些会讲故事的人。事实上,在经济的上行期,绝大多数伟大的企业都擅长讲故事。当然,从经济学的角度看,换一个说法也可以在经济的上行期,绝大多数伟大的企业都擅长
中国体操女神周捷的人生路嫁1米58奥运五金王前国家体操队健将,素来有体操女神美称的周捷,今年刚刚生下二胎,如今儿女双全,生活美满幸福。她的比赛生涯没能留下太多惊艳的成就,但她的丈夫邹凯却是体操界堪比李宁的存在,被称为奥运五金一生幸福平安开启美好的一天。祝愿远方的朋友平安,健康又幸福。人与人之间的相遇是因为缘分。这世界上没有无缘无故的遇见,每一次遇见,每一份缘都是最美好的因缘际会。我要给您送上一整串的祝福开心快乐平当你不想努力了,看看这些名人名言杨绛1。你的问题主要在于读书不多,而想的太多。2。一个人经过不同程度的锻炼,就获得不同程度的修养不同程度的效益。好比香料,捣得愈碎,磨得愈细,香得愈浓烈。3。懒惰也是天生的,勤奋需他年过半百参加八路军,医术高超救治无数战友,建国后被授予中校在抗战历史中白求恩医院是一个不朽的丰碑,就是在革命根据地这个简陋的医院里挽救了无数抗战英雄,不过在当时的这所医院里还出现了一位年过花甲才参加八路军的老战士。这位老战士虽然奋战在后方2022年轻人生活消费观察报告外经济作为今年的大热门,各位品牌能否赶得上今年的末班车?那明年的户外经济消费趋势又是如何?那今天这份报告各位品牌们千万不要错过。这份报告就是年轻人生活消费观察户外社交片。获得这份报服装色彩分析(一)谈服装就离不开谈色系,一款好的设计产品,没有色系的衬托就好比红花没绿叶,同一个色系会有色差,色差对服装的销量影响很大,还是用实物做比较,直接明了。图左泛白图右带米色这是昨天客户发过这世上最温暖的情话一定是我懂,懂你作者王娜原创作品禁止转载秋之美,如梦如幻。秋之幽,如深如绘。秋之爱,如风如水。秋天的你,何时走出我的梦里?回到真实的人生里,真情相许。总有一种风景,让你一生不忘。总有一个人,让你流愿望与现实愿望总归是美好的丰满的现实总归是真实的骨感的。我们的愿望也许已经实现或许还在实现的路上也有可能是已经遗忘在生活的某一个角落,拾起已经尘土飞扬。小时候都有理想和愿望,以前的愿望能够实能令你大彻大悟的几句话,你看懂了吗?一人生活的是心情,凭的是好的心态。人生,什么好都不如心情好。只有每天保持好的心情,维持一个健康平和的心态,这样的人生才是最令人感到幸福的。其实,谁的人生都是如此,不要只看到人家光鲜灯塔夜读丨做一个温暖的人,向阳而生1hr温暖两个字,读起来便让人唇齿间暖意盎然。像阳光亲吻草木,像三月的微风轻抚脸颊,像母亲对孩子的爱,穿透心灵润泽生命。温暖的人,真诚真实有烟火气有人情味。温暖的人,具有朴素纯净的雪里蕻最好吃腌法,奶奶用了60年的秘方,一不小心被我泄露,真香导语奶奶用了60年的秘方,一不小心被我泄露,腌雪里蕻不能直接抹盐,想要味道香还入味,不霉不臭,这1步不能少!一餐一饭,心有所栖。柴米油盐,爱有所依。静看一树花开,慢享三餐四季。大家