5 thoughts on “How much is + ‘x’ ?

  1. Jeffrey Kemp

    Very interesting. Obviously the parser is ignoring the + operator in this instance.

    select dump(0) zero, dump(+’x’) plus_x, dump(‘x’) x, dump(+’0′) plus_zero_char, dump(+0) plus_zero from dual;

    ZERO PLUS_X X PLUS_ZERO_CHAR PLUS_ZERO
    —————- —————– —————– —————- —————-
    Typ=2 Len=1: 128
    Typ=96 Len=1: 120
    Typ=96 Len=1: 120
    Typ=96 Len=1: 48
    Typ=2 Len=1: 128

    Unfortunately SELECT – ‘x’ FROM DUAL; doesn’t work so we may never know what a negative character would be.

  2. Sokrates

    works also for date, timestamp and interval – literals:

    [email protected] > select +date'2012-04-14', +timestamp'2012-04-14 22:48:00', +interval '1' year from dual;

    +DATE'2012-04-14' +TIMESTAMP'2012-04-1422:48:00' +INTERVAL'1'YEAR
    ------------------- ----------------------------------- -----------------
    14.04.2012 00:00:00 14-APR-12 10.48.00.000000000 PM +01-00

    doesn’t seem to be documented though

  3. Laurent Schneider Post author

    while this works :

    select (-1)* ( interval '1' year ) from dual;
    -01-00

    why shouldn’t this work ?

    select - interval '1' year from dual;
    ORA-00932: inconsistent datatypes: expected NUMBER got INTERVAL YEAR TO MONTH

    if Oracle knows that +x=x, it should also know that -x=(-1)*x, right?

  4. Gary Pennington

    I would think parser bug, probably stripping optional leading unary + for numerics. Also ‘works’ on columns and ( ).

    SQL> SELECT +(+(+’z’))||+dummy FROM dual;

    +(

    zX

Comments are closed.