【代码保留】Oracle删除字符串空格

功能:

删除字符串中隐含空格

思路:

将字符串中的所有空格' '替换为''(将中间有空格的替换为中间无空格的字串)。

SQL:

select replace(a.tar_regid,' ','') tar_regid from red_taskregister a where  a.tar_id = 226

实例:

tar_id = 226的项我为之添加了空格。

select a.tar_regid from red_taskregister a where  a.tar_id = 226

select replace(a.tar_regid,' ','') tar_regid from red_taskregister a where  a.tar_id = 226

第一句将不去除空格,第二句则删除空格。为了看到效果,我分别在其左右并上框。

select '['||a.tar_regid||']' from red_taskregister a where  a.tar_id = 226

select '['||replace(a.tar_regid,' ','')||']' tar_regid from red_taskregister a where  a.tar_id = 226

于是结果分别为:

[      ]

[]

原文地址:https://www.cnblogs.com/volnet/p/962221.html