SQL Server:1 ++ 2 是什么意思? [英] SQL Server: What does 1 ++ 2 mean?

查看:51
本文介绍了SQL Server:1 ++ 2 是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

SELECT 1 + 2 --3
SELECT 1 ++ 2 --3
SELECT 1 ++++++ 2 --3
SELECT 1 + '2' --3
SELECT 1 ++ '2' --3
SELECT '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?

推荐答案

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

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))

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

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.

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

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.

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

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

除了常用的算术运算符、加、减、乘、除、一元加和一元减之外,还有以下返回数字的函数:...

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

虽然一元加号并不是那么有用,但它有一个更有用的伙伴:一元减号.它也被称为否定运算符.

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

这篇关于SQL Server:1 ++ 2 是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆