Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Mailing Lists -> Oracle-L -> Re: I was told there would be no (date) math
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-lReceived on Thu Apr 13 2006 - 12:19:01 CDT