programing

Oracle Date TO_CHAR('Month DD, YYY')에 추가 공간이 있습니다.

instargram 2023. 7. 11. 21:28
반응형

Oracle Date TO_CHAR('Month DD, YYY')에 추가 공간이 있습니다.

내가 할 때...

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

다음을 확인할 수 있습니다.

July      01, 2011
April     01, 2011
January   01, 2011

왜 내 달과 하루 사이에 여분의 공간이 있습니까?왜 그것들을 서로 옆에 두지 않는 거지?

왜 내 달과 하루 사이에 여분의 공간이 있습니까?왜 그것들을 서로 옆에 두지 않는 거지?

따라서 출력이 정렬됩니다.

패딩을 원하지 않는 경우 형식 한정자 사용FM:

SELECT TO_CHAR (date_field, 'fmMonth DD, YYYY') 
  FROM ...;

참조:모델 수정자 형식 지정

'Month'를 to_char 오른쪽 패드에 9자로 사용하는 경우, 줄여서 'MON'을 사용하거나 to_char를 사용한 후 트리밍 및 연결해야 합니다.자세한 내용은 http://www.techonthenet.com/oracle/functions/to_char.php 을 참조하십시오.

select trim(to_char(date_field, 'month')) || ' ' || to_char(date_field,'dd, yyyy')
  from ...

또는

select to_char(date_field,'mon dd, yyyy')
  from ...  

빈 공간을 삭제하려면 fm 요소를 사용해야 합니다.

SELECT TO_CHAR(sysdate, 'fmDAY DD "de" MONTH "de" YYYY') CURRENT_DATE
FROM   dual;
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

사용해 보십시오.

select to_char(to_date('01/10/2017','dd/mm/yyyy'),'fmMonth fmDD,YYYY') from dual;

select to_char(sysdate,'fmMonth fmDD,YYYY') from dual;

Dual에서 to_char(sysdate, 'DD-fmMONT-YY') "날짜"를 선택합니다;

위 질의 결과는 아래와 같습니다.

날짜.

01-4월-2019년

언급URL : https://stackoverflow.com/questions/7166446/oracle-date-to-charmonth-dd-yyyy-has-extra-spaces-in-it

반응형