Mysql:修剪数据库中的所有字段 [英] Mysql:Trim all fields in database

查看:82
本文介绍了Mysql:修剪数据库中的所有字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UPDATE mytable SET mycolumn= LTRIM(RTRIM(mycolumn));

在修剪列中删除尾部空格时效果很好,但是如何调整它以修剪所有列而不必在表中写下每个列名?因为我有一个庞大的数据库.

works fine on trimming columns removing trailer spaces, but how can i adjust it to trim all columns without having to write each column name in table ?? cause i kind have a huge database.

推荐答案

晚了几年,但可能会帮助其他人: 此代码修剪表"your_table"的所有字段. 可以扩展为以相同的方式在整个数据库上工作....

Some years late, but might help others: This code trims all fields of a the table "your_table". Could be expanded to work on the whole database in the same way....

SET SESSION group_concat_max_len = 1000000;
select concat('update your_table set ',group_concat(concat('`',COLUMN_NAME, '` = trim(`',COLUMN_NAME,'`)')),';')
   FROM INFORMATION_SCHEMA.COLUMNS
    WHERE table_name = 'your_table'
    into @trimcmd;

prepare s1 from @trimcmd;
execute s1;
DEALLOCATE PREPARE s1;

这篇关于Mysql:修剪数据库中的所有字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆