什么是运算符 |在 sql 中及其运作方式

what is operator | in sql and how it works

我想知道以下条件是如何工作的:

where x1 | x2 | x3 | x4 is not null

x1、x2、x3、x4 列可以为空 一样吗?

where x1 is not null or  x2 is not null or   x3 is not null or x4 is not null

这是按位或。你find details here.

试试这个:

DECLARE @int1 INT=0xFF00; --        => 65280
DECLARE @int2 INT=0x000F; --        =>    15
DECLARE @int3 INT=@int1 | @int2; -- => 65295 

SELECT @int1,@int2,@int3,
       CAST(@int3 AS BINARY(2));--  => 0xFF0F

可以看到@int1@int2的位掩码合并为0xFF0F

这可用于检查或设置特殊位或一组位。