Ok, this is perhaps a quirkiness of the Oracle parser.
The following query works. Note the + before 'Y' on the last line.
SELECT *
FROM (SELECT 'Y' AS field FROM DUAL
UNION ALL
SELECT 'X' AS field FROM DUAL) t
WHERE t.field = +'Y'
Why is the Oracle parser accepting this? For a second I thought it was because of the old outer join syntax but in that syntax the + is surrounded with parentheses.
This works as well:
select +'Y1' from dual;
and this:
select 'A' || + 'Y1' from dual;
This works (oracle converts the string to a number):
select -'1' from DUAL;
but not this ([Error] Execution (223: 9): ORA-01722: invalid number ):
select -'A' from DUAL;
I wonder why the + can be used before a varchar2 value. The Arithmetic Operators section doesn't mention specific rules that would apply to string values.
The unary +
operator is defined as identity See the Table 4-1 "SQL Operator Precedence" in About SQL Operators.
Also:
select + date '2015-01-01' from dual;
January, 01 2015 00:00:00
Edited to add.
"Identity" being to return its argument. For another example from a different language see Clojure's identity
function. Wikipedia has a page for "identity function".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With