表列中的 oracle 修剪数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5260724/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 23:00:23  来源:igfitidea点击:

oracle trim data in a table col

sqloracle

提问by kralco626

I know that Oracle has the TRIMfunction and I would like to use it to trim the whitespace out of a field in one of my tables.

我知道 Oracle 有这个TRIM功能,我想用它来修剪我的一个表中字段中的空白。

As such:

像这样:

update THIRD_PARTY_ADRS_INFO_TEMP
set HOUSE_NO = TRIM(HOUSE_NO);

just hangs when i try to run it in SQL Developer.

当我尝试在 SQL Developer 中运行它时挂起。

I have also tried TRIM(' ' from HOUSE_NO)and REPLACE(HOUSE_NO,' ','')all with the same effect

我也试过TRIM(' ' from HOUSE_NO)REPLACE(HOUSE_NO,' ','')效果都一样

This seems like it should be really simple...

这看起来应该很简单......

ideas?

想法?

回答by Tony Andrews

If it "hangs" then this suggests that your session is blocked by another session. You are trying to update every row in the table; if another session has locked a row in the same table and not yet committed your session will have to wait.

如果它“挂起”,则表明您的会话被另一个会话阻止。您正在尝试更新表中的每一行;如果另一个会话锁定了同一个表中的一行并且尚未提交,您的会话将不得不等待。

回答by Michael Broughton

Glad you solved the row lock. As to removing all sorts of blank space, you can also look into REGEXP_REPLACE if on a recent Oracle version. It is a bit slower than trim, but if you have multiple possible non-printing characters to deal with it might be worth a look.

很高兴你解决了行锁。至于删除各种空格,如果在最近的 Oracle 版本上,您还可以查看 REGEXP_REPLACE。它比修剪慢一点,但是如果您有多个可能的非打印字符要处理,则可能值得一看。

e.g.

例如

select regexp_replace(x,'[[:space:]|[:blank:]|[:cntrl:]]*$','')
   from (select 'ad f cde  '||chr(10)||chr(13)||chr(8)||' ' as x from dual);

回答by Greg Reynolds

How many rows in your table? You could try just doing a select rather than an update (with rownum < 10 for example) just to satisfy yourself that it's working.

您的表中有多少行?您可以尝试只进行选择而不是更新(例如,rownum < 10)只是为了让自己满意它正在工作。