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

Home -> Community -> Mailing Lists -> Oracle-L -> Re: I was told there would be no (date) math

Re: I was told there would be no (date) math

From: Richard Ji <richard.c.ji_at_gmail.com>
Date: Thu, 13 Apr 2006 13:19:01 -0400
Message-ID: <b4d52f20604131019v11c6b46ai911e0e5c5ba43ab4@mail.gmail.com>


Without the parenthesis, the whole thing is evaluated from left to right. So the first trunc(sysdate) - trunc(sysdate) results in 0, then it becomes 0 - trunc(sysdate) so you get inconsistent data type. The error message is a bit confusing though.

In the second try with the parenthesis, the expression within the parenthesis is evaluated first which is 0. Then it becomes trunc(sysdate) - 0 and that's a simple date arithmetic.

Richard Ji

On 4/13/06, Jesse, Rich <Rich.Jesse_at_qg.com> wrote:
> Hey all,
>
> While debugging an analytical function issue using 9.2.0.5, I run this
> idiotic query:
>
> SELECT TRUNC(SYSDATE) - TRUNC(SYSDATE) - TRUNC(SYSDATE)
> FROM DUAL;
>
> And it errors out with:
>
> ORA-00932: inconsistent datatypes: expected DATE got DATE
>
> (In 10.2, the verbage is modified to "expected JULIAN DATE got DATE")
>
> Add parenthesis and it works:
>
> SELECT TRUNC(SYSDATE) - (TRUNC(SYSDATE) - TRUNC(SYSDATE))
> FROM DUAL;

--
http://www.freelists.org/webpage/oracle-l
Received on Thu Apr 13 2006 - 12:19:01 CDT

Original text of this message

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