How To Use Comparison Operators In Oracle
Description
Comparison operators are used in where clause. Comparison operator is represented by special character or keywords. The data items are called the operands or the arguments.
Comparison operator gives the result value True, False, Null or 0, 1.
Comparison | Operator Description |
= | Equal |
!= | Not Equal |
<> | Not Equal |
> | Greater Than |
>= | Greater Than Equal To |
< | Less Than |
<= | Less Than Equal TO |
Equal Operator
Equal operator is represented by =
Syntax
- Select * from table_name
- Where condition;
Example
- Select * from Employee
- where Emp_Id = 7001;
Not Equal Operator
Not Equal Operator is represented by !=
Syntax
- Select * from table_name
- Where condition;
Example
- Select * from Employee
- where Emp_Id != 7002;
Not Equal Operator
Not equal operator is represented by <>
Both the operators <> or != gives the same results.
Syntax
- Select * from table_name
- Where condition;
Example
- Select * from Employee
- where Emp_Id <> 7002;
Greater Than Operator
Greater than operator is represented by <
Syntax
- Select * from table_name
- Where condition;
Example
- Select * from Employee
- where Emp_Id > 7003;
Greater Than Equal To Operator
Greater than equal to operator is represented by >=
Syntax
- Select * from table_name
- Where condition;
Example
- Select * from Employee
- where Emp_Id >= 7003;
Less Than Operator
Less Than Operator is represented by <
Syntax
- Select * from table_name
- Where condition;
- Select * from Employee
- where Emp_Id < 7003;
Less Than Equal To Operator
Less Than Equal To Operator is represented by <=
Syntax
- Select * from table_name
- Where condition;
- Select * from Employee
- where Emp_Id <= 7003;
Advanced Operators
Comparison | Operator Description |
IN () | For matching value in a list. |
Not | For Negates Operand |
Between | It represents the range |
Is Null | Null Value |
Is Not Null | Non-Null Values |
Like | Matching the pattern |
IN () Operator
Expression
Expression IN(value1, value2 ….. value_n)
Syntax
- Select * from Table_name
- Where IN Condition;
This example uses the character value.
- Select *
- From Employee
- Where Emp_name=’Smith’;
IN Operator Example with Numeric
Syntax
- Select * from
- table_name
- Where IN Condition;
Example
- Select * from Employee
- Where Emp_id IN(7001, 7002,7003);
- Example using Not Operator
Syntax
- Select * from
- table_name
- Where NOT IN Condition;
Example
- Select * from Employee
- Where Emp_id NOT IN(7001, 7002,7003);
Between Operator
Expression
Expression Between value 1 and value 2;
Syntax
- Select * From table_name
- Where Between value1 and value2;
Example
- Select * From Employee
- Where Emp_id Between 7004 and 7008;
IS Null Operator
Expression
Expression is Null
Syntax
- Select * From table_name
- Where Column_name is Null;
- Select * From Employee
- Where Emp_id is Null;
IS NOT Null Operator
Expression
Expression Is not Null
Syntax
- Select * From table_name
- Where Column_name is Not Null;
Example
- Select * From Employee
- Where Emp_id is Not Null;
Like Operator
Expression
Expression Like Pattern[‘escape character’]
Syntax
- Select Column_name
- From table_name
- where Column_name Like ‘ ’;
- Select Emp_name
- From Employee
- where Emp_name Like ‘Ki_g’;
Summary
Thus, we learnt, Comparison operators are used in where clause. Comparison operator is represented by a special character or keywords. Comparison operator gives the result value True, False, Null or 0, 1. We learned, how to use these operators with examples.