Oracle and clauses

Source: Internet
Author: User
Tags logical operators

In this tutorial, you will learn how to AND combine two or more Boolean expressions using the Oracle operator.

The Oracle and operator describes

ANDThe operator is a logical operator that combines a Boolean expression and returns if all two expressions are true true . If one of the expressions is false, the AND operator returns false .

ANDThe syntax of the operator is as follows:

expression_1 AND expression_2

The following table describes the AND true results of using an operation that conforms to and, false and NULL values-

value TRUE FALSE NULL
TRUE TRUE FALSE Null
FALSE FALSE FALSE FALSE
Null Null FALSE Null

Typically, the criteria used in the WHERE clause of the SELECT,DELETE and UPDATE statements AND to form matching data. In addition, the operator is used in the predicate of the join clause AND to form the join condition.

When using more than one logical operator in a declaration, Oracle always evaluates the AND operator first. However, you can use parentheses to change the order of evaluations.

Examples of Oracle and operators

See the following order () table in the sample database orders :

1. Oracle ANDExample of a combination of two Boolean expressions

The following example finds the orders with the customer number as 2 pending ( Pending ):

SELECT order_id, customer_id, status, TO_CHAR(order_date,‘YYYY-MM-DD‘) AS order_dateFROM ordersWHERE  status = ‘Pending‘  AND customer_id = 2ORDER BY order_date;

In this example, the query returns all the order information that satisfies both expressions, namely:

status = ‘Pending‘

And

customer_id = 2

Execute the above query statement to get the following result:

2. Oracle and the example of combining more than two Boolean expressions

You can use multiple AND operators to combine Boolean expressions.

For example, the following statement retrieves an order that meets all of the following conditions:

    • Placed in the 2017 year.
    • Responsible for the salesperson number 60 .
    • There is a delivery status.

Refer to the following query statement-

SELECT    order_id,    customer_id,    status,    TO_CHAR(order_date, ‘YYYY-MM-DD‘) AS order_dateFROM    ordersWHERE    status = ‘Shipped‘    AND salesman_id = 60    AND EXTRACT(YEAR FROM order_date) = 2017ORDER BY    order_date;

Execute the above query statement to get the following results-

3. Examples of Oracle and and or operators combined

You can AND combine operators with other logical operators, such as OR and NOT , to form a condition.

For example, the following query ID finds 44 an order for the customer, and the status is canceled (Canceled) or pending (Pending). Refer to the following implementation statement-

SELECT    order_id,    customer_id,    status,    salesman_id,    TO_CHAR(order_date, ‘YYYY-MM-DD‘) AS order_dateFROM    ordersWHERE    (status = ‘Canceled‘ OR status = ‘Pending‘)    AND customer_id = 44ORDER BY    order_date;

Execute the above query statement to get the following results-

In this tutorial, we have learned how to use AND the Oracle operator to combine two or more Boolean expressions.


Oracle and clauses

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.