fun sql

How much is + ‘x’ ?

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

SQL> select + 'x' from dual;


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

By Laurent Schneider

Oracle Certified Master

5 replies on “How much is + ‘x’ ?”

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;

—————- —————– —————– —————- —————-
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 PM +01-00

doesn’t seem to be documented though

while this works :

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

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;



Leave a Reply

Your email address will not be published.