Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does a plus sign in a SQL WHERE clause (WHERE + userName = SYSTEM_USER)

Tags:

sql-server

I am stuck on trying to find the meaning of a plus sign in a where clause. Anyone have any ideas on this one? Been stuck for a bit on it. The query itself is pretty simple and work similarly with, or with without the plus sign. I'd like to remove it unless it's there for a reason.

SELECT userID from tblUser WHERE + userName = SYSTEM_USER

Added note: This is in SQL Server 2008 not Oracle, nor did it come from and Oracle migration... As mentioned below there is an older join notation for Oracle that uses the + generally postfixed to some of the criteria.

like image 429
RyanInAK Avatar asked Dec 08 '25 03:12

RyanInAK


1 Answers

The unary + operator is simply a no op. This is explained in the documentation for this operator, which is here:

Although a unary plus can appear before any numeric expression, it performs no operation on the value returned from the expression. Specifically, it will not return the positive value of a negative expression. To return positive value of a negative expression, use the ABS function.

I actually believe this remark is a wee little bit misleading. I think the unary plus operator will convert a string argument to a number. When applied to a constant string filled with digits, this could actually be beneficial as a way of encouraging the compiler to use an index on a numeric field.

like image 185
Gordon Linoff Avatar answered Dec 15 '25 09:12

Gordon Linoff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!