微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

sql-server – SQL Server:1 2是什么意思?

sql Server的T-sql语法似乎允许连续多个加号:
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'

多个优点似乎像一个加号一样.为什么“多加运算符”存在?它有什么作用?

解决方法

一个加号被解释为一个加法运算符.每个剩余的加号被解释为 unary plus operator
1 ++ 2   means   1 + (+2)
1 +++ 2  means   1 + (+(+2))

在编程语言中使用这个一元加运算符非常普遍,尽管它在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.

一元加号运算符在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: …

一元加号并不是那么有用,它有一个更有用的伴侣:一元减.它也被称为negative operator.

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

原文地址:https://www.jb51.cc/mssql/81283.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐