SQL Server:1 ++ 2是什么意思?

时间:2021-07-16 01:13:05

SQL Server's T-SQL syntax seems to allow multiple plus signs in succession:

SQL Server的T-SQL语法似乎允许连续多个加号:

SELECT 1 + 2 --3SELECT 1 ++ 2 --3SELECT 1 ++++++ 2 --3SELECT 1 + '2' --3SELECT 1 ++ '2' --3SELECT '1' + '2' --'12'SELECT '1' ++ '2' --'12'

Multiple pluses seem to behave just like a single plus. Why does the "multiple plus operator" ++ exist? What does it do?

多个加号似乎表现得像一个加号。为什么存在“多重运算符”++?它有什么作用?

2 个解决方案

#1


15  

The first plus sign is interpreted as an addition operator. Each of the remaining plus signs is interpreted as a unary plus operator:

第一个加号被解释为加法运算符。每个剩余的加号都被解释为一元加号运算符:

1 ++ 2   means   1 + (+2)1 +++ 2  means   1 + (+(+2))

It's very common in programming languages to have this unary plus operator, though it's rarely used in SQL as it doesn't actually do anything.

在编程语言中使用这个一元加运算符是很常见的,尽管它在SQL中很少使用,因为它实际上没有做任何事情。

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.

尽管一元加号可以出现在任何数值表达式之前,但它不会对表达式返回的值执行任何操作。具体来说,它不会返回否定表达式的正值。

The unary plus operator is mentioned in the SQL-92 standard.

SQL-92标准中提到了一元加运算符。

As well as the usual arithmetic operators, plus, minus, times, divide, unary plus, and unary minus, there are the following functions that return numbers: ...

除了通常的算术运算符,plus,minus,times,divide,unary plus和unary minus之外,还有以下函数返回数字:...

While unary plus isn't all that useful, it has a more useful companion: unary minus. It is also known as the negative operator.

虽然一元加号并不是那么有用,但它有一个更有用的伴侣:一元减去。它也被称为负算子。

SELECT -(expression), ...--     ^ unary minus

#2


3  

SELECT 1 ++ 2 means 1 plus (+2) which means 3

SELECT 1 ++ 2表示1加(+2),表示3

Same logic for the others 1+(+(+2)) and so on

其他1 +(+(+ 2))的逻辑相同,依此类推

SELECT '1' + '2' --'12' you are concatenating 2 strings, string '1' and string '2', which results '12'

SELECT'1'+'2' - '12'你连接2个字符串,字符串'1'和字符串'2',结果为'12'

#1


15  

The first plus sign is interpreted as an addition operator. Each of the remaining plus signs is interpreted as a unary plus operator:

第一个加号被解释为加法运算符。每个剩余的加号都被解释为一元加号运算符:

1 ++ 2   means   1 + (+2)1 +++ 2  means   1 + (+(+2))

It's very common in programming languages to have this unary plus operator, though it's rarely used in SQL as it doesn't actually do anything.

在编程语言中使用这个一元加运算符是很常见的,尽管它在SQL中很少使用,因为它实际上没有做任何事情。

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.

尽管一元加号可以出现在任何数值表达式之前,但它不会对表达式返回的值执行任何操作。具体来说,它不会返回否定表达式的正值。

The unary plus operator is mentioned in the SQL-92 standard.

SQL-92标准中提到了一元加运算符。

As well as the usual arithmetic operators, plus, minus, times, divide, unary plus, and unary minus, there are the following functions that return numbers: ...

除了通常的算术运算符,plus,minus,times,divide,unary plus和unary minus之外,还有以下函数返回数字:...

While unary plus isn't all that useful, it has a more useful companion: unary minus. It is also known as the negative operator.

虽然一元加号并不是那么有用,但它有一个更有用的伴侣:一元减去。它也被称为负算子。

SELECT -(expression), ...--     ^ unary minus

#2


3  

SELECT 1 ++ 2 means 1 plus (+2) which means 3

SELECT 1 ++ 2表示1加(+2),表示3

Same logic for the others 1+(+(+2)) and so on

其他1 +(+(+ 2))的逻辑相同,依此类推

SELECT '1' + '2' --'12' you are concatenating 2 strings, string '1' and string '2', which results '12'

SELECT'1'+'2' - '12'你连接2个字符串,字符串'1'和字符串'2',结果为'12'