-- 问题重现
set @v_t=' ';
select hex(@v_t)
-- 原因:
-- ASCII格式的hex进展ox09对应char为(ht)制表tab,喔原来是有很多的制表符吧.
-- 数据库中去掉的办法
set @v_t=' ';
select f_sql_clearspace(' ');
-- java中的解决方法:
replace("\\t","")
CREATE DEFINER=`root`@`%` FUNCTION `f_sql_clearspace`(v_sql varchar()) RETURNS varchar() CHARSET utf8
begin
declare v_tmps varchar() default '';
declare v_last varchar() default '';
declare v_curr varchar() default '';
declare v_num int default ;
declare v_max int default ; set v_max = length(v_sql);
while v_num <> v_max do
set v_num = v_num + ;
set v_curr = substr(v_sql, v_num, ); if (v_curr = char() or v_curr = char()) then
set v_curr = char();
end if; if (v_curr <> char() and (v_last is null or v_last <> char())) then
set v_tmps = concat(v_tmps, v_curr);
set v_last = v_curr;
elseif (v_last <> char() and v_curr = char()) then
set v_tmps = concat(v_tmps, v_curr);
set v_last = v_curr;
elseif (v_last = char() and v_curr <> char()) then
set v_tmps = concat(v_tmps, v_curr);
set v_last = v_curr;
end if;
end while; return v_tmps;
end