Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

to_char(sysdate,'DAY') question

oraLaroFeb 4 2020 — edited Feb 4 2020

see this in 12.1 and 12.2, hope its an easy one, I feel sure Ive seen this before.

Why does oracle pad the result of to_char(date_field,'DAY') to max length of 9 which Id guess is to handle WEDNESDAY.

I have other options like D or DY to get the day I want without trimming but just wondering why that pad is there, is it expected behaviour.   And no Im not going to do anything different when I find out.

SQL> select '-' || to_char(sysdate-3,'DAY') || '-' ,

  2         '-' || to_char(sysdate-2,'DAY') || '-' , 

  3         '-' || to_char(sysdate-1,'DAY') || '-' ,

  4         '-' || to_char(sysdate,'DAY') || '-' ,

  5         '-' || to_char(sysdate+1,'DAY') || '-' ,

  6         '-' || to_char(sysdate+2,'DAY') || '-' ,

  7         '-' || to_char(sysdate+3,'DAY') || '-'

  8                from dual;

'-'||TO_CHAR(SYSDATE-3,'DAY')||'-'     '-'||TO_CHAR(SYSDATE-2,'DAY')||'-'     '-'||TO_CHAR(SYSDATE-1,'DAY')||'-'     '-'||TO_CHAR(SYSDATE,'DAY')||'-'       '-'||TO_CHAR(SYSDATE+1,'DAY')||'-'          '-'||TO_CHAR(SYSDATE+2,'DAY')||'-'     '-'||TO_CHAR(SYSDATE+3,'DAY')||'-'

-------------------------------------- -------------------------------------- -------------------------------------- -------------------------------------- -------------------------------------- -------------------------------------- --------------------------------------

-SATURDAY -                            -SUNDAY   -                            -MONDAY   -                            -TUESDAY  -                            -WEDNESDAY-        -THURSDAY -                             -FRIDAY   -

SQL>

Comments
Post Details
Added on Feb 4 2020
2 comments
418 views