我通过csv导入数据后,发现表中的数据却查不出来,原来是因为字段中含有换行符这些特殊字符了,把它们去掉就能正常查询了。
MySQL查询去除水平制表符、回车符、换行符
去除水平制表符(tab键 或者 \t):
UPDATE your_table_name SET filed = replace(str,char(9),'')
去除回车符(Enter键)
UPDATE your_table_name SET filed = replace(str,char(13),'')
去除换行符(\n):
UPDATE your_table_name SET filed = replace(str,char(10),'')
一块去除Tab 符、换行符、回车符:
UPDATE your_table_name SET filed = replace(replace(replace(filed,char(9),''), char(10), ''), char(13), '')
MySQL去除某个字符:
UPDATE ingredients SET functional = replace(`functional`,'?',''); #去除“?”
UPDATE price SET theprice = replace(`theprice`,'元',''); #去除“元”
mysql去除中间空格replace
UPDATE your_table_name SET filed = replace(`filed`,' ','');
mysql去除字段首位空格trim
UPDATE your_table_name SET filed = trim(filed);
mysql去除字段左侧空格ltrim
UPDATE your_table_name SET filed = ltrim(filed);
mysql去除字段右侧空格rtrim
UPDATE your_table_name SET filed = rtrim(filed);