| (ビット演算子 OR) (Transact-SQL)| (Bitwise OR) (Transact-SQL)
適用対象:Applies to: SQL ServerSQL Server (サポートされているすべてのバージョン)
SQL ServerSQL Server (all supported versions)
Azure SQL データベースAzure SQL Database
Azure SQL データベースAzure SQL Database
Azure SQL Managed InstanceAzure SQL Managed Instance
Azure SQL Managed InstanceAzure SQL Managed Instance
Azure Synapse AnalyticsAzure Synapse Analytics
Azure Synapse AnalyticsAzure Synapse Analytics
Parallel Data WarehouseParallel Data Warehouse
Parallel Data WarehouseParallel Data Warehouse
SQL ServerSQL Server (サポートされているすべてのバージョン)
SQL ServerSQL Server (all supported versions)
Azure SQL データベースAzure SQL Database
Azure SQL データベースAzure SQL Database
Azure SQL Managed InstanceAzure SQL Managed Instance
Azure SQL Managed InstanceAzure SQL Managed Instance
Azure Synapse AnalyticsAzure Synapse Analytics
Azure Synapse AnalyticsAzure Synapse Analytics
Parallel Data WarehouseParallel Data Warehouse
Parallel Data WarehouseParallel Data Warehouse
Transact-SQLTransact-SQL ステートメントの中で、バイナリ式に変換された 2 つの指定される整数値に対して、ビットごとの論理和演算を実行します。Performs a bitwise logical OR operation between two specified integer values as translated to binary expressions within Transact-SQLTransact-SQL statements.
Transact-SQL 構文表記規則
Transact-SQL Syntax Conventions
構文Syntax
expression | expression
注意
SQL Server 2014 以前の Transact-SQL 構文を確認するには、以前のバージョンのドキュメントを参照してください。To view Transact-SQL syntax for SQL Server 2014 and earlier, see Previous versions documentation.
引数Arguments
式 (expression)expression
整数データ型に分類されるデータ型、または bit、または binary または varbinary データ型の有効な 式を指定します。Is any valid expression of the integer data type category, or the bit, binary, or varbinary data types. 式 は、ビットごとの演算に対して 2 進数として扱われます。expression is treated as a binary number for the bitwise operation.
注意
ビットごとの演算では、1 つの 式 のみが binary または varbinary データ型のいずれかになります。Only one expression can be of either binary or varbinary data type in a bitwise operation.
戻り値の型Result Types
入力値が int の場合は int、入力値が smallint の場合は smallint、入力値が tinyint の場合は tinyint を返します。Returns an int if the input values are int, a smallint if the input values are smallint, or a tinyint if the input values are tinyint.
解説Remarks
ビットごとの | 演算子は、2 つの式の対応するビットを対象にビットごとの論理和演算を実行します。The bitwise | operator performs a bitwise logical OR between the two expressions, taking each corresponding bit for both expressions. 入力式の中で現在処理の対象にあるビットについて、いずれかのビットまたは両方のビットが 1 の値を持つ場合、結果セットのビットは 1 に設定されます。入力式のビットが両方とも 1 の値を持たない場合、結果セットのビットは 0 に設定されます。The bits in the result are set to 1 if either or both bits (for the current bit being resolved) in the input expressions have a value of 1; if neither bit in the input expressions is 1, the bit in the result is set to 0.
左側の式と右側の式が異なる整数型の場合 (たとえば、左側の 式 が smallint 型で、右側の 式 が int 型の場合)、小さいデータ型の引数が大きいデータ型の引数に変換されます。If the left and right expressions have different integer data types (for example, the left expression is smallint and the right expression is int), the argument of the smaller data type is converted to the larger data type. この例では、smallintexpression は int に変換されます。In this example, the smallintexpression is converted to an int.
例Examples
この例では、元の値を示すために int データ型を使用するテーブルを作成し、このテーブルに 1 行挿入します。The following example creates a table with int data types to show the original values and puts the table into one row.
CREATE TABLE bitwise (
a_int_value INT NOT NULL,
b_int_value INT NOT NULL);
GO
INSERT bitwise VALUES (170, 75);
GO
このクエリは、a_int_value 列と b_int_value 列との間でビットごとの論理和演算を実行します。The following query performs the bitwise OR on the a_int_value and b_int_value columns.
SELECT a_int_value | b_int_value
FROM bitwise;
GO
結果セットは次のようになります。Here is the result set.
-----------
235
(1 row(s) affected)
170 (a_int_value または下記の A
) をバイナリで表すと 0000 0000 1010 1010
です。The binary representation of 170 (a_int_value or A
, below) is 0000 0000 1010 1010
. 75 (b_int_value または下記の B
) をバイナリで表すと 0000 0000 0100 1011
です。The binary representation of 75 (b_int_value or B
, below) is 0000 0000 0100 1011
. この 2 つの値に対してビットごとの論理和演算を実行すると、結果はバイナリで 0000 0000 1110 1011
、10 進数では 235 になります。Performing the bitwise OR operation on these two values produces the binary result 0000 0000 1110 1011
, which is decimal 235.
(A | B)
0000 0000 1010 1010
0000 0000 0100 1011
-------------------
0000 0000 1110 1011
参照See Also
演算子 (Transact-SQL) Operators (Transact-SQL)
ビットごとの演算子 (Transact-SQL) Bitwise Operators (Transact-SQL)
|= (ビットごとの OR 代入) (Transact-SQL) |= (Bitwise OR Assignment) (Transact-SQL)
複合演算子 (Transact-SQL)Compound Operators (Transact-SQL)