EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials Database Management Tutorial PL/SQL BETWEEN
Secondary Sidebar
Data Structure Interview Questions

Career In Devops

What is MySQL?

MATLAB Technical Computing

Data Mining Applications

Lean Analytics

PL/SQL BETWEEN

PL_SQL BETWEEN

Introduction to PL/SQL BETWEEN

PL/SQL BETWEEN clause is the operator used in PL/SQL to recognize whether a particular value lies between the specified values of the parameters that are specified in the between function. The between function returns a Boolean value that can be either true or false. If the specified value is between the range of the values specified in ascending format in the parameters of the between, we get true or in other case, we get a false value. Here we will see how we can make the use of between clause in PL/SQL, the usage of the function and the implementation along with the examples.

Syntax of PL/SQL BETWEEN

The syntax of the PL/SQL BETWEEN operator is given below:

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Expression/ column value BETWEEN lower value of range AND higher value of range

In the above syntax, the expression can be any value which evaluates to a single value which can be either string or number depends on the range of value that we have specified in lower and higher value of range.

The between clause or operator will return a true value only when we have specified the range such that the value fits in it and satisfies the following conditions:

  • Column value or evaluated expression value > = lower value of range
  • Column value or evaluated expression value < = higher value of range

NOT BETWEEN

There is one more version of BETWEEN which is NOT BETWEEN. This operator works in a reverse manner than that of the BETWEEN operator. It is just the negation of the BETWEEN operator.

The syntax of NOT BETWEEN clause is as shown below:

Expression/ column value NOT BETWEEN lower value of range AND higher value of range

The NOT BETWEEN clause returns a true value when the specified expression value or the value of the column does not lies in between the lower and higher values of the range and false if the value is within the range.

This means that the NOT BETWEEN clause satisfies following conditions:

  • Column value or evaluated expression value < lower value of range
  • Column value or evaluated expression value > higher value of range

Examples of PL/SQL BETWEEN

Given below are the examples of PL/SQL BETWEEN:

Example #1

Suppose, we have one table named employee_details that stores the details and information about the employees of a particular multinational company. We want to retrieve the details of only that employees and staff whose salary is between the range of 10000 and 20000. In this case, we can make the use of between operator in where clause of our query statement. Firstly, let us retrieve all the data of the table employee_details and study its contents by using the following query statement.

Code:

SELECT * FROM [employee_details];

The output of the execution of the above query statement is as shown below retrieving all the rows of employee_details table.

Output:

PL/SQL BETWEEN 1

Now, to retrieve only specific data belonging to the group who have their salary between 10000 and 20000, we can make the use of following query statement.

Code:

SELECT
f_name as "First Name", l_name as "Last Name",
email_id as "Email Id", mobile_number as "Mobile Number",
joining_date as "Joining Date", salary
FROM [employee_details] WHERE salary
BETWEEN 10000 AND 20000;

The output of execution of above query statement is as shown below retrieving all the rows of employee_details table whose salary is between 10000 and 20000 inclusive.

Output:

PL/SQL BETWEEN 2

Example #2

Consider one more table named contact details which is present in our database and helps to store the additional contact details of the employees in it. Let us firstly see the contents of this table by executing the following query statement.

Code:

SELECT * FROM [contact_details]

The output of execution of above query statement is as shown below retrieving all the rows of contact_details table.

Output:

PL/SQL BETWEEN 3

Now, to retrieve only specific data belonging to the group who have their employee ids between 108 and 112, we can make the use of following query statement.

Code:

SELECT employee_id,
employee_name as "Name of Employee",
city as "Living Area",
mobile_number as "Contact Details"
FROM [contact_details] WHERE employee_id
BETWEEN 108 AND 112;

The output of execution of above query statement is as shown below retrieving all the rows of contact_details table whose employee id is between 108 and 112 inclusive.

Output:

retrieve only specific data belonging to the group

Example #3

Let us take one more example where we will try to retrieve all the records of the contact details table having the employees whose employee id does not lie between the range of 108 and 112. This can be simply done by changing the above query statement and replacing the occurrence of BETWEEN operator with NOT BETWEEN operator.

Code:

SELECT employee_id, employee_name as "Name of Employee",
city as "Living Area", mobile_number as "Contact Details"
FROM [contact_details] WHERE
employee_id NOT BETWEEN 108 AND 112;

The output of execution of above query statement is as shown below retrieving all the rows of contact_details table whose employee id is not between 108 and 112.

Output:

does not lie between the range of 108 and 112

Example #4

We can even make the use of the BETWEEN operator in the query statement to retrieve the records having the certain column whose values are actually not numbers but strings. Let us consider the same table employee_details. Suppose, we want to retrieve the records whose name of the employee begins with a character that lies between K and T. In that case, we can use our between operator in our query statement in the following way.

Code:

SELECT
f_name as "First Name", l_name as "Last Name",
email_id as "Email Id", mobile_number as "Mobile Number",
joining_date as "Joining Date", salary
FROM [employee_details] WHERE f_name
BETWEEN 'K' AND 'T';

The output of execution of above query statement is as shown below retrieving all the rows of employee_details table whose employee names begin with a character that is in between K and T.

Conclusion

We can make the use of the between operator in where clause of select, delete of update statements in PL/SQL. The between operator helps us to specify the range that a certain column should belong to while retrieving the result set.

Recommended Articles

This is a guide to PL/SQL BETWEEN. Here we discuss the introduction, NOT BETWEEN and examples of PL/SQL BETWEEN respectively. You may also have a look at the following articles to learn more –

  1. Triggers in PL/SQL
  2. PL/SQL Collections
  3. PL/SQL Data Types
  4. Loops in PL/SQL
Popular Course in this category
Oracle Training (17 Courses, 8+ Projects)
  17 Online Courses |  8 Hands-on Projects |  140+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

SQL Training Program (10 Courses, 8+ Projects)4.9
PL SQL Training (4 Courses, 2+ Projects)4.8
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more