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

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 'EastRiver' 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...