如何删除varchar列的空白区域 [英] how to remove the blank space of a varchar column

查看:68
本文介绍了如何删除varchar列的空白区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的一个表中,我有一个varchar列,即''cityarea_name''。在某些行中,此列数据以空格(一个字符)开头。我不知道它是如何发生的。

任何人都可以建议我一个确切的SQL查询来纠正这个''cityarea_name''列。我想删除这个起始空白区域,仅用于实际发生的那些行。



谢谢。

In one of my tables I have a varchar column namely ''cityarea_name''. In some of the rows, this column data starts with a blank space (one character). I dont know how it happenned.
Can anyone suggest me an exact sql query for rectifying this ''cityarea_name'' column. I want to remove this starting blank space only for those rows where actually it has happenned.

Thanks.

推荐答案

您可以简单地对所有记录执行更新,如下所示:
You could simply perform an update on all the records like this:
UPDATE MyTable
SET cityarea_name = LTRIM(cityarea_name)

没有理由缩小更新范围,因为如果你尝试做某事,你可能会放慢更新速度像这样:

There''s no reason to narrow down the scope of the update because you will probably slow down the update if you try to do something like this:

UPDATE MyTable
SET cityarea_name = LTRIM(cityarea_name)
WHERE LEFT(cityarea_name, 1) = ' '

这篇关于如何删除varchar列的空白区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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