当前位置: 代码迷 >> Sybase >> Sybase的SQL怎么去掉字符串中间的空格
  详细解决方案

Sybase的SQL怎么去掉字符串中间的空格

热度:8040   发布时间:2013-02-26 00:00:00.0
Sybase的SQL如何去掉字符串中间的空格?
SQL code
select StringReplace(' dfdd   df dfd',' ','')



返回仍然是“ dfdd df dfd”...貌似空格替换不走,苦闷!!


------解决方案--------------------------------------------------------
用str_replace 函数
 
SQL code
select str_replace(' abc bcd cde def', ' ', '');
------解决方案--------------------------------------------------------
http://forums.databasejournal.com/archive/index.php/t-40207

Sybase doesnt have a replace cmd. you have to use a combo of charindex and stuff to replace it.

you could have the following to replace ur string.

SQL code
declare   @my_var   char(25)     select   @my_var   =   'abc|ert|rfrfrf|'     while   charindex('|',   @my_var)   >   0     begin     select   @my_var   =   stuff(@my_var,   charindex('|',   @my_var),   1,   ';')     end     select   @my_var
------解决方案--------------------------------------------------------
Maybe you can have a try with str_replace function?

SQL code
  str_replace(strexpression1,strexpression2,strexression3)