Need to trim blank space in oracle

谁说胖子不能爱 提交于 2019-12-02 11:04:28

Use Trim Function

select Trim(trailing ' ' from 'xxxxxxxxxx yyyyyyyyy - 12/7/14 - 12/13/14   ') from dual

or Use Rtrim

select RTrim('xxxxxxxxxx yyyyyyyyy - 12/7/14 - 12/13/14   ') from dual

I would use REGEXP_REPLACE() in the event that there were other whitespace charaters like tabs in there:

SELECT REGEXP_REPLACE(mydata, '\s+$') AS mydata
  FROM mytable

Hope this helps. If TRIM() isn't working then I suspect you have something other than spaces trailing.

If you know that the data is going to end with a digit, you might also try the following:

SELECT REGEXP_REPLACE(mydata, '\D+$') AS mydata
  FROM mytable

The \D in the regex matches everything but a digit, so any trailing characters not a digit 0-9 will be trimmed.

We also can trim left and right side blank spaces using below approach

SELECT LTrim(RTrim('xxxxxxxxxx yyyyyyyyy - 12/7/14 - 12/13/14   ')) FROM dual
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!