How To Use Special Operator In Oracle
Description
• Some Operator
• All operator
Exists operator is frequently used with the correlated subqueries. If the value exists, it returns TRUE; if it does not exists, it returns false.
• This operator produces a Boolean result.
• It takes a sub query as the arguments and evaluates it to true, if the sub query produces any output and false, if the subquery does not produce any output.
• Used along with the relational operators.
• Similar to IN Operator, not only used in subqueries.
The “any” operator compares the lowest value from the set.
“Some” and “any” operator can be used interchangeably.
Thus, we learnt, special operators are used in subqueries. We learnt, how to use these special operators with the examples.
Some special operators used in subqueries are-
• Exists Operator
• Any operator• Some Operator
• All operator
Exists Operator
Not Exists operator is more reliable, if the subquery returns any null values.
• This operator is used to check for the existence of values.• This operator produces a Boolean result.
• It takes a sub query as the arguments and evaluates it to true, if the sub query produces any output and false, if the subquery does not produce any output.
Example
- SELECT * FROM employee
- WHERE EXISTS (SELECT * FROM departments
- WHERE employee.emp_id = departments.Emp_id);
Any Operator
• Similar to IN Operator, not only used in subqueries.
• “some” and “any” operator can be used interchangeably.
List the employee names, whose salary is less than the lowest salary of an employee belonging to dept_no 102.
Example
- Select Emp_name from employee
- where salary < any (select salary from employee where dept_no = 102);
Some Operator
- Select Emp_name from employee
- where salary < Some (select salary from employee where dept_no = 102);
All Operator
In “All” operator, the predicate is true, if every value selected by the subquery satisfies the condition in the predicate of the outer query.
Example
- Select Emp_name from employee
- where salary > ALL (select salary from employee where dept_no = 107);
Summary