程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> 關於MYSQL數據庫 >> mysql二元分詞法函數_MySQL教程

mysql二元分詞法函數_MySQL教程

編輯:關於MYSQL數據庫

DELIMITER $$;

DROP FUNCTION IF EXISTS `radius`.`fun_split`$$

CREATE DEFINER=`root`@`%` FUNCTION `fun_split`(nm varchar(100)) RETURNS varchar(500) CHARSET latin1
    READS SQL DATA
BEGIN
      declare i int;
      declare rtn int;
      declare rtn1 int;
      declare sec varchar(10);
      declare rtnstr varchar(500);
          set i=1;
      set rtnstr='';
          WHILE i <length(nm) DO
      set rtn= ascii(substring(nm,i,1));
      IF rtn>127 THEN
         set rtn1= ascii(right(substring(nm,i,2),1));
         IF rtn1> 127 THEN
            IF i<length(nm)-1 THEN
          IF (ascii(right(substring(nm,i,3),1))>127 and ascii(right(substring(nm,i,4),1))>127) THEN
             set sec=concat(right(concat('00',rtn-160),2),right(concat('00',rtn1-160),2),right(concat('00',ascii(right(substring(nm,i,3),1))-160),2),right(concat('00',ascii(right(substring(nm,i,4),1))-160),2),' ');
          ELSE
             set sec='';
          END IF;
            ELSE
          set sec='';
            END IF ;
         ELSE
            set sec=concat(char(rtn),char(rtn1));
         END IF;
         SET i = i + 1;
      ELSE
         IF i<length(nm)-1 THEN
          IF (ascii(right(substring(nm,i,2),1))>127 and ascii(right(substring(nm,i,3),1))>127) THEN
              set sec=concat(char(rtn),' ');
          ELSE
              set sec=char(rtn);
          END IF;
         ELSE
          IF (ascii(right(substring(nm,i,2),1))>127 and ascii(right(substring(nm,i,3),1))>127) THEN
              set sec=char(rtn);
          ELSE
              set sec=char(rtn,ascii(right(substring(nm,i,2),1)));
          END IF;
         END IF;
        
      END IF;
      set rtnstr=concat(rtnstr,sec);
      SET i = i + 1;
     
      END WHILE;
       RETURN rtnstr;
      END$$

DELIMITER ;$$

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved