0% found this document useful (0 votes)
5 views

PRACTICAL NO-4 Perform Queries To Retrieve Data From Tables With Different Predicates

Uploaded by

barot kajal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

PRACTICAL NO-4 Perform Queries To Retrieve Data From Tables With Different Predicates

Uploaded by

barot kajal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Practical 4

Aim: Perform queries to retrieve data from tables with different


predicates (LIKE, BETWEEN, IN) etc.
A predicate is simply an expression that evaluates to TRUE, FALSE, or UNKNOWN. Predicates are
typically employed in the search condition of WHERE and HAVING clauses, the join conditions of
FROM clauses, as well as any other part of a query where a boolean value is required.

There are numerous types of predicates, including:

 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

 > Greater than

 < Less than

 >= Greater than or equal to

 <= Less than or equal to

 <> Not equal to

Hence, a comparison predicate takes the form of:

expression_1 comparison_operator expression_2

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.

The IS NULL predicate takes the following form:

IS [NOT] NULL

For example, the expression x IS NULL is TRUE if x is a 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));

 insert into Job values('&job_id','&job_title','&min_sal','&max_sal');

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));

 insert into Employee values


('01','&emp_name','&emp_sal','&emp_comm','&dept_no');

3. Create table deposit_gtu(a_no varchar2 (5),cname varchar2 (15),bname varchar2


(10),amount number (7,2), a_date date);

 insert into deposit_gtu values('&a_no','&cname','&bname','&amount','&a_date');

4. Create table borrow_gtu(loanno varchar2 (5),cname varchar2 (15),bname varchar2


(10),amount number (7,2));

 insert into borrow_gtu values('&loanno','&cname','&bname','&amount');

1. Retrieve all data from employee, jobs and deposit.

 select * from Employee;

 select * from Job;

 select * from deposit_gtu;

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';

3. Display all jobs with minimum salary is greater than 4000.

 select * from Job where min_sal>4000;

4. Display name and salary of employee whose department no is 20. Give alias name to name
of employee.

 select emp_name "name of employee",emp_sal "salary of employee" from


employee where dept_no=20;

5. Display employee no,name and department details of those employee whose department
lies in(10,20)

 select EMP_NO,EMP_NAME,DEPT_NO from EMPLOYEE where DEPT_NO BETWEEN


10 and 20;

You might also like