Oracle Date TO_CHAR('Month DD, YYYY') has extra spaces in it

前端 未结 6 1713
渐次进展
渐次进展 2020-12-03 10:18

When I do...

Select TO_CHAR (date_field, \'Month DD, YYYY\')
from...

I get the following:

July      01, 2011
April     01,          


        
6条回答
  •  盖世英雄少女心
    2020-12-03 10:57

    SQL> -- original . . .
    SQL> select
      2  to_char( sysdate, 'Day "the" Ddth "of" Month, yyyy' ) dt
      3  from dual;
    
    DT
    ----------------------------------------
    Friday    the 13th of May      , 2016
    
    SQL>
    SQL> -- collapse repeated spaces . . .
    SQL> select
      2  regexp_replace(
      3      to_char( sysdate, 'Day "the" Ddth "of" Month, yyyy' ),
      4      '  * *', ' ') datesp
      5  from dual;
    
    DATESP
    ----------------------------------------
    Friday the 13th of May , 2016
    
    SQL>
    SQL> -- and space before commma . . .
    SQL> select
      2  regexp_replace(
      3      to_char( sysdate, 'Day "the" Ddth "of" Month, yyyy' ),
      4      '  *(,*) *', '\1 ') datesp
      5  from dual;
    
    DATESP
    ----------------------------------------
    Friday the 13th of May, 2016
    
    SQL>
    SQL> -- space before punctuation . . .
    SQL> select
      2  regexp_replace(
      3      to_char( sysdate, 'Day "the" Ddth "of" Month, yyyy' ),
      4      '  *([.,/:;]*) *', '\1 ') datesp
      5  from dual;
    
    DATESP
    ----------------------------------------
    Friday the 13th of May, 2016
    

提交回复
热议问题