Oracle Tutorial

  • Home
  • Start Here
  • Basics
  • Advanced
    • Oracle View
    • Oracle Index
    • Oracle Synonym
    • Oracle Sequence
    • Oracle Administration
  • PL/SQL
  • Functions
    • Aggregate Functions
    • Analytic Functions
    • Comparison Functions
    • Date Functions
    • String Functions
  • API
    • Python Oracle
Home / Oracle Basics / Oracle ALL

Oracle ALL

Summary: in this tutorial, you will learn how to use the Oracle ALL operator to compare a value with a list or subquery.

Introduction to the Oracle ALL operator

The Oracle ALL operator is used to compare a value to a list of values or result set returned by a subquery.

The following shows the syntax of the ALL operator used with a list or a subquery:

operator ALL ( v1, v2, v3) operator ALL ( subquery)

In this syntax:

  • The ALL operator must be preceded by an comparison operator such as =, != >,>=, <, <= and followed by a list or subquery.
  • The list or subquery must be surrounded by the parentheses.

When you use the ALL operator to compare a value to a list, Oracle expands the initial condition to all elements of the list and uses the AND operator to combine them as shown below:

SELECT * FROM table_name WHERE c > ALL ( v1, v2, v3 ); -- transform the ALL operator SELECT * FROM table_name WHERE c > v1 AND c > v2 AND c > v3;

If you use the ALL operator to compare a value with a result set returned by a subquery, Oracle performs a two-step transformation as shown below:

SELECT product_name, list_price FROM products WHERE list_price > ALL ( SELECT list_price FROM products WHERE category_id = 1 ) ORDER BY product_name; -- 1st step: transformation that uses ANY SELECT product_name, list_price FROM products p1 WHERE NOT( p1.list_price <= ANY (SELECT list_price FROM products p2 WHERE category_id = 1 )) ORDER BY product_name; -- 2nd step: transformation that eliminates ANY SELECT product_name, list_price FROM products p1 WHERE NOT EXISTS (SELECT p2.list_price FROM products p2 WHERE p2.category_id = 1 AND p2.list_price >= p1.list_price ) ORDER BY product_name;

If the subquery returns no rows, then the following condition evaluates to true:

operator ALL (subquery)

Which means that the query that uses the above condition in the WHERE clause will return all rows in case the subquery return no rows.

SELECT * FROM table_name WHERE col operator ALL(subquery);

Oracle ALL operator examples

The following example finds the average list price of products in each product category:

SELECT ROUND( AVG( list_price ),2 ) avg_list_price FROM products GROUP BY category_id ORDER BY avg_list_price DESC;
Oracle ALL example

1) col > ALL (list)

The expression evaluates to true if the col is greater than the biggest value in the list.

For example, the following query finds all products whose list prices are greater than the highest price of the average price list:

SELECT product_name, list_price FROM products WHERE list_price > ALL( SELECT AVG( list_price ) FROM products GROUP BY category_id ) ORDER BY list_price ASC;
Oracle ALL with greater than operator

2) col < ALL(list)

The expression evaluates to true if the col is smaller than the smallest value in the list.

For example, the following query finds all products whose list prices are less than the lowest price in the average price list:

SELECT product_name, list_price FROM products WHERE list_price < ALL( SELECT AVG( list_price ) FROM products GROUP BY category_id ) ORDER BY list_price DESC;
Oracle ALL with less than operator

3) col >= ALL(list)

The expression evaluates to true if the col is greater than or equal to the biggest value in the list.

The following statement returns CPU products whose list price is greater than or equal to 2200:

SELECT product_name, list_price FROM products WHERE list_price >= ALL( 1000, 1500, 2200 ) AND category_id = 1 ORDER BY list_price DESC;
Oracle ALL with greater than or equal operator

3) col <= ALL(list)

The expression evaluates to true if the col is less than or equal to the smallest value in the list.

The following statement returns the CPU products whose list price is less than or equal to 977.99, which is the smallest value in the list.

SELECT product_name, list_price FROM products WHERE list_price <= ALL( 977.99, 1000, 2200 ) AND category_id = 1 ORDER BY list_price DESC;
Oracle ALL with less than or equal operator

5) col = ALL ( list)

The expression evaluates to true if the col matches all values in the list.

6) col != ALL (list)

The expression evaluates to true if the col does not match any values in the list.

In this tutorial, you have learned how to use the Oracle ALL operator to compare a value with a list or subquery.

  • Was this tutorial helpful?
  • YesNo
Previous Oracle ANY
Next Oracle GROUPING SETS

Getting Started

  • What Is Oracle Database
  • Install Oracle Database Server
  • Download Oracle Sample Database
  • Create Oracle Sample Database
  • Connect To Oracle Database Server

Oracle Data Manipulation

  • SELECT
  • Oracle DUAL Table
  • ORDER BY
  • SELECT DISTINCT
  • WHERE
  • Table & Column Aliases
  • AND
  • OR
  • FETCH
  • BETWEEN
  • IN
  • LIKE
  • IS NULL
  • Joins
  • INNER JOIN
  • LEFT JOIN
  • RIGHT JOIN
  • FULL OUTER JOIN
  • CROSS JOIN
  • Self Join
  • GROUP BY
  • HAVING
  • UNION
  • INTERSECT
  • MINUS
  • GROUPING SETS
  • CUBE
  • ROLLUP
  • PIVOT
  • UNPIVOT
  • INSERT
  • INSERT INTO SELECT
  • INSERT ALL
  • UPDATE
  • DELETE
  • MERGE
  • Subquery
  • Correlated Subquery
  • EXISTS
  • NOT EXISTS
  • ANY
  • ALL

Oracle Data Types

  • Oracle Data Types
  • NUMBER
  • FLOAT
  • BINARY_FLOAT
  • CHAR
  • NCHAR
  • VARCHAR2
  • NVARCHAR2
  • DATE
  • INTERVAL
  • TIMESTAMP
  • TIMESTAMP WITH TIME ZONE

Oracle Data Definition

  • CREATE TABLE
  • Identity Column
  • ALTER TABLE
  • ALTER TABLE ADD Column
  • ALTER TABLE MODIFY Column
  • Drop Columns
  • DROP TABLE
  • TRUNCATE TABLE
  • RENAME Table
  • Oracle Virtual Column

Oracle Constraints

  • PRIMARY KEY
  • FOREIGN KEY
  • UNIQUE
  • CHECK
  • NOT NULL

Oracle Views

  • CREATE VIEW
  • DROP VIEW
  • Updatable Views
  • Inline Views
  • WITH CHECK OPTION

About Oracle Tutorial

OracleTututorial.com website provides Developers and Database Administrators with the updated Oracle tutorials, scripts, and tips.

Search

Recent Tutorials

  • Oracle Implicit Statement Results
  • Calling PL/SQL Stored Functions in Python
  • Calling PL/SQL Procedures in Python
  • Managing Transaction in Python
  • Deleting Data From Oracle Database in Python

Site Links

  • Oracle Books
  • About
  • Contact
  • Privacy Policy
  • Terms of Use

Copyright © 2021 Oracle Tutorial. All Rights Reserved.