Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.tools -> Re: strange behavior of decode?

Re: strange behavior of decode?

From: Matt Foster <matt_foster_uk_at_yahoo.co.uk>
Date: 2000/08/11
Message-ID: <3994360C.16D57A05@yahoo.co.uk>#1/1

Maurice Samuels wrote:
>
> can anyone explain to me why this does not work:
>
> select to_char(sysdate,'Day') from dual;
> output -> Friday
>
> select decode(to_char(sysdate,'Day'),'Friday',1,2) from dual;
> output -> 2
>
> why is the output not 1?
>
> if i do:
> select decode(to_char(sysdate,'Dy'),'Fri',1,2) from dual;
> output -> 1
>
> why does the decode work in this case but not the previous?
> any help would be much appreciated.
> -maurice
> samuels_at_seas.upenn.edu

SQL> select to_char(sysdate,'Day') from dual;

TO_CHAR(S



Friday

SQL> select length(to_char(sysdate,'Day')) from dual;

LENGTH(TO_CHAR(SYSDATE,'DAY'))


                             9

In other words when the date format is changed to 'Day' a VARCHAR2(9) is created to accommodate for a Wednesday.

Try

SQL> select decode(to_char(sysdate,'Day'),'Friday ',1,2) from dual;

DECODE(TO_CHAR(SYSDATE,'DAY'),'FRIDAY',1,2)


                                          1

HTH, MF

-- 
matt_foster_uk_at_yahoo.co.uk
Received on Fri Aug 11 2000 - 00:00:00 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US