Logical operator AND, OR, NOT
The logical operators limits rows based on logical conditions. The logical operators are:
Operator | Description |
---|---|
x AND y | Returns true when both x and y are true |
x OR y | Returns true when either x or y is true |
NOT x | Returns true if x is false, and returns false if x is true |
Using AND:
CREATE TABLE EMP (EMPNO NUMBER(4) NOT NULL,
ENAME VARCHAR2(10),
HIREDATE DATE);
INSERT INTO EMP VALUES (1, NULL, TO_DATE('17-DEC-1980', 'DD-MON-YYYY'));
INSERT INTO EMP VALUES (2, 'ALLEN', TO_DATE('20-FEB-1981', 'DD-MON-YYYY'));
INSERT INTO EMP VALUES (3, 'WARD', TO_DATE('22-FEB-1981', 'DD-MON-YYYY'));
INSERT INTO EMP VALUES (4, 'JONES', TO_DATE('2-APR-1981', 'DD-MON-YYYY'));
INSERT INTO EMP VALUES (5, 'MARTIN',TO_DATE('28-SEP-1981', 'DD-MON-YYYY'));
SQL> SELECT *
2 FROM emp
3 WHERE empno > 1
4 AND ENAME ='JONES' ;
EMPNO ENAME HIREDATE
---------- ---------- ---------
4 JONES 02-APR-81
SQL>
SQL>
SQL>
Using OR operator :
SQL> SELECT *
2 FROM emp
3 WHERE empno > 1
4 OR ename = 'JONES';
EMPNO ENAME HIREDATE
---------- ---------- ---------
2 ALLEN 20-FEB-81
3 WARD 22-FEB-81
4 JONES 02-APR-81
5 MARTIN 28-SEP-81
SQL>
Home »
Oracle »
Select »
Oracle »
Select »
Where:
- Where clause
- dual table
- Comparison Operators
- ANY
- ALL
- LIKE, NOT LIKE
- IN, NOT IN
- Between...AND, NOT Between...AND
- IS NULL, IS NOT NULL
- Logical operator AND, OR, NOT
- Operator Precedence for AND, OR, NOT
Related: