我有一个SQL语句是这样的:select * from rkbasicinfo where gmsfhm='"+gmsfhm+"',其中gmsfhm在oracle数据库中有可能有空格,我想把在字符串后面的空格给去掉,但是在字符串前面或字符串里面的空格是不能去的,请问各位高手这个sql语句该怎么写,谢谢!!
select * from rkbasicinfo where rtrim(gmsfhm) = '"+gmsfhm+"'
REPLACE('string','s1','s2') string 希望被替换的字符或变量 s1 被替换的字符串 s2 要替换的字符串 SQL> select replace('he love you','he','i') from dual;REPLACE('H ---------- i love youYours: select replace(yourstring,' ','') from yourtable;
SQL> select replace('you are a boy',' ','') from dual;REPLACE('Y ---------- youareaboy
select * from rkbasicinfo where replace(gmsfhm,' ','')='"+gmsfhm+"',
可是我只能去掉字符串后面的空格如:“ I love you ”,我要去了I love you后面的空格,前面和中间的空格是不能去的,请问有什么好的办法?
select * from rkbasicinfo where rtrim(gmsfhm) = '"+gmsfhm+"' 只去除gmsfhm字段右边,也就是后面的空格,ex: select 1 from dual where rtrim(' i love you ') = ' i love you'
string 希望被替换的字符或变量
s1 被替换的字符串
s2 要替换的字符串
SQL> select replace('he love you','he','i') from dual;REPLACE('H
----------
i love youYours: select replace(yourstring,' ','') from yourtable;
----------
youareaboy
只去除gmsfhm字段右边,也就是后面的空格,ex:
select 1 from dual where rtrim(' i love you ') = ' i love you'
LTRIM 删除左边出现的字符串
RTRIM 删除右边出现的字符串
SQL> select ltrim(rtrim(' gao qian jing ',' '),' ') from dual;LTRIM(RTRIM('
-------------
gao qian jing
rtrim: right trim
去空格基本上就是以下几个函数:ltrim,rtrim,trim和replace