Mysql 字符串首尾空字符处理

1:查询表字段是否包含首尾空字符方式

select * from t where length(g_barcode) != length(trim(g_barcode)) ;

select * from t where g_barcode like '% ' or  g_barcode like ' %';

select * from t where right(g_barcode,1)='' or left(g_barcode,1) ='' ;

2:处理字段首尾空格方式

update t set g_barcode=trim(g_barcode)  where goods_id=2177;

update t set g_barcode=replace(g_barcode, ' ', '')  where goods_id=2177;

 

你可能感兴趣的:(数据库)