How much is + ‘x’ ?

Sounds like an april fool, but I wonder what is + ‘x’ supposed to do 🙂

SQL> select + 'x' from dual;

+
-
x

it does not convert to number as 0 + ‘1’ would do

5 Comments

  • 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.

  • works also for date, timestamp and interval – literals:

    sokrates@11.2 > 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

  • 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?

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

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

    +(

    zX

Leave a Reply

Your email address will not be published.