일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
- Date and Time Function
- Data and Time Functions
- 전자정부표준프레임워크
- MySQL
- String Functions and Date Operators
- Oracle
- 티베로
- String Function and Operators
- Tibero
- Sring Functions and Operators
- HTTP
- 방화벽
- 윈도우
- String Functions and Operators
- 전자정부 표준프레임워크
- Date and Time Functions
- 오라클
- SVN
- Today
- Total
웹이야기
MySQL 논리 연산자 본문
Logical Operators
논리연산자쯤 되겠지.
Name | Description |
AND, && | Logical AND |
NOT, ! | Legates value |
OR, || | Logical OR |
XOR | Logical XOR |
In SQL, all alogical operators evaluates to TRUE, FALSE, or NULL (UNKNOWN). In MySQL, these are implemented as 1(TRUE), 0(FALSE), and NULL. Most of this is common to different SQL database aserver, although some servers may return any nonzero value for TRUE.
MySQL evaluates any nonzero, non-NULL values to TRUE,
1. NOT, !
Logical NOT.
Evalutes to 1 if the operand is 0, to 0 if the operand is nonzero, and NOT NULL.
mysql>SELECT NOT 10;
--> 0
mysql>SELECT NOT 0;
--> 1
mysql>SELECT NOT NULL;
--> NULL
mysql>SELECT ! (1+1);
--> 0
mysql>SELECT ! 1+1;
--> 1
The last exapmle produces 1 because the rexpression evaluages the same way as (!1)+1.
The !, operator is a nonstandard MYSQL extension, As of MySQL 8.0.17, this operator is deprecated and support for it will be removed in a future MySQL version. Applicatios should be adjusted to use the standard SQL NOT operator.
! 보다는 NOT을 쓰자
2. AND, &&
Logical AND.
Evaluates to 1 if all operands are nonzero and not NULL, to 0 if one or more operands are 0, otherwise NULL is returned.
mysql>SELECT 1 AND 1;
--> 1
mysql>SELECT 1 AND 0;
--> 0
mysql>SELECT 1 AND NULL;
--> NULL
mysql>SELECT 0 AND NULL;
--> 0
mysql>SELECT NULL AND 0;
--> 0
3. OR , ||
Logical OR.
When both operands are non-NULL, the result is 1 if any operand is nonzero, and 0 otherwise. with a NULL operand, the result is 1 if the other operand is nonzero, and NULL otherwise. If both operands are NULL, the result is NULL.
mysql>SELECT 1 OR 1;
--> 1
mysql>SELECT 1 OR 0;
--> 1
mysql>SELECT 0 OR 0;
--> 1
mysql>SELECT 0 OR NULL;
--> NULL
mysql>SELECT 1 OR NULL;
--> 1
4. XOR
Logical XOR.
Returns NULL if either operand is NULL. For non-NULL operands, evaluages to 1 if an odd number of operands is nonzero, otherwise 0 is returned.
mysql>SELECT 1 XOR 1;
--> 0
mysql>SELECT 1 XOR 0;
--> 1
mysql>SELECT 1 XOR NULL;
--> NULL
mysql>SELECT 1 XOR 1 XOR 1;
--> 1
a XOR b is mathematically equal to ( a AND (NOT b)) OR ((NOT a) AND b).
흠.. 이거는 보기는 많이 봤지만... 정말 써본적은 한번도 없는 것 같다.
'D > MySQL' 카테고리의 다른 글
MySQL Control Flow Functions (0) | 2020.03.19 |
---|---|
MySQL 지정 연산자 (0) | 2020.03.19 |
MySQL 비교 연산자(MySQL 8.x 기준) (0) | 2020.03.18 |
MySQL AUTO_INCREMENT 값 수정 (0) | 2020.03.13 |
MySQL 테이블 인덱스 보기 (0) | 2020.03.12 |