SQL BIT_XOR function
XORs the values of a group together bit by bit.
- 카테고리
- Aggregates
- Returns
integer- In this category
- 43 of 52
구문
BIT_XOR(x) | BIT_XOR_AGG(x)
엔진 지원
| 엔진 | Support | 메모 |
|---|---|---|
| SQL Server | Not built in | No built-in equivalent. |
| PostgreSQL | 예 | PostgreSQL 14+ aggregate; # is the scalar XOR operator |
| MySQL | 예 | empty or all-NULL group returns 0 |
| SQLite | Not built in | No built-in equivalent. |
| Oracle | Different name or syntax | 21c+: BIT_XOR_AGG; empty or all-NULL group returns 0 |
예시
MySQL
SELECT BIT_XOR(id) FROM nodes;
Oracle
SELECT BIT_XOR_AGG(checksum) FROM chunks;
알아 두면 좋은 정보
- XOR is self-inverse: any value that appears an even number of times cancels out, which powers parity checks and find-the-odd-one-out tricks.
- MySQL and Oracle return 0 for empty and all-NULL groups, the XOR identity; PostgreSQL returns NULL.
- NULLs are skipped.
Questions about BIT_XOR
What is BIT_XOR good for?
Parity checks, cheap checksums and the classic 'every id appears twice, find the odd one' puzzle: XOR all ids.
What does an empty group return?
0 in MySQL and Oracle, NULL in PostgreSQL.
Why does XOR-ing twice cancel?
x XOR x = 0, so feeding the same values again restores the identity.
Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.
Related on SQLly
Cheat sheets for the engines that have it: PostgreSQL, MySQL, Oracle.
Functions your engine actually has
SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.