mysql获取中文字段内容

来源:互联网 发布:linux 漏洞扫描软件 编辑:程序博客网 时间:2024/06/01 07:49
############################################################
create table test
(
id int,
info varchar(255)
);
insert into test values(1,'abc中国123');
insert into test values(1,'abc123韩国');
insert into test values(1,'日本abc中国123');
insert into test values(1,'还有吗');


############################################################
drop FUNCTION getinfo;
CREATE FUNCTION getinfo(in_string VARCHAR(255))
   RETURNS VARCHAR(255)
 BEGIN
   DECLARE l_new_string VARCHAR(255);
   DECLARE char_str1 varchar(255);
   DECLARE char_str2 varchar(255);
   DECLARE STR_LEN int;
   DECLARE i int;
set char_str1='';
set STR_LEN=CHAR_LENGTH(in_string);
set i=0;  
lp1 : LOOP
if !(SUBSTRING(in_string,i,1) regexp "[\u0391-\uFFE5]") then
set char_str1=CONCAT(char_str1,SUBSTRING(in_string,i,1));
end if;
if i > STR_LEN then
leave lp1;
end if;
set i = i+1;
end LOOP;
  RETURN(char_str1);
end;
############################################################
select info,getinfo(info) from test;
############################################################

0 0
原创粉丝点击