PRACTICAL NO-4 Perform Queries To Retrieve Data From Tables With Different Predicates
PRACTICAL NO-4 Perform Queries To Retrieve Data From Tables With Different Predicates
Comparison
LIKE
BETWEEN
IN
EXISTS
IS NULL (/INTEGER/DECIMAL/FLOAT...)
In the remainder of this article, we'll examine a few examples of the above Predicate types.
Comparison Predicates
Any time that we use a comparison operator in an expression, such as WHERE employee_salary >
100000, we are constructing a Predicate that evaluates to TRUE, FALSE, or UNKNOWN. Comparison
operators include:
= Equal to
In a comparison predicate, expression2 can also be a subquery. If the subquery does not return any
rows, the comparison predicate evaluates to FALSE.
LIKE Predicate
IN SQL, the number one pattern-matching predicate is the LIKE operator, as it compares column
values with a specified pattern. Like works with any character or date data type. Here's an example:
BETWEEN Predicate
The BETWEEN operator specifies a range, which determines the lower and upper bounds of
qualifying values. For instance, in the Predicate income BETWEEN 5000 AND 20000 the selected data
is a range of greater then or equal to 5000 and less then or equal to 20000. The Between operator
can be used with numeric, text and date data types. Here's an example:
IN Predicate
An IN operator allows the specification of two or more expressions to be used for a query search. The
result of the condition is TRUE if the value of the corresponding column equals one of the
expressions specified by the IN predicate:
EXISTS Predicate
The EXISTS Predicate accepts a subquery as an argument. It returns TRUE if the subquery returns one
or more rows, and returns FALSE if it returns zero rows.
Here's an example:
IS NULL Predicate
Use IS NULL to determine whether an expression is null, because you cannot test for null by using the
= comparison operator. When applied to row value expressions, all elements must test the same.
IS [NOT] NULL
IS UNKNOWN is a synonym for IS NULL when the expression is of the BOOLEAN type.
Here's a query that uses the IS NOT NULL Predicate to fetch all actors whose last name is a non-NULL
value:
1. create table Job ( job_id varchar2 (15), job_title varchar2 (30) , min_sal number (7,2) ,
max_sal number (7,2));
2. create table Employee (emp_no number (3), emp_name varchar2 (30), emp_sal number
(8,2), emp_comm number (6,1), dept_no number (3));
2. Give details of account no. and deposited rupees of customers having account opened
between dates 01-01-06 and 25-07-06.
select ACTNO,AMOUNT from DEPOSIT where ADATE BETWEEN '01-JAN-06' and '25-
JUL-03';
4. Display name and salary of employee whose department no is 20. Give alias name to name
of employee.
5. Display employee no,name and department details of those employee whose department
lies in(10,20)