OceanBase logo

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Resources

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS

OceanBase Cloud

OceanBase Database

Tools

Connectors and Middleware

QUICK START

OceanBase Cloud

OceanBase Database

BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Company

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

International - English
中国站 - 简体中文
日本 - 日本語
Sign In
Start on Cloud

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS
OceanBase CloudOceanBase Database
ToolsConnectors and Middleware
QUICK START
OceanBase CloudOceanBase Database
BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

Start on Cloud
编组
All Products
    • Databases
    • iconOceanBase Database
    • iconOceanBase Cloud
    • iconOceanBase Tugraph
    • iconInteractive Tutorials
    • iconOceanBase Best Practices
    • Tools
    • iconOceanBase Cloud Platform
    • iconOceanBase Migration Service
    • iconOceanBase Developer Center
    • iconOceanBase Migration Assessment
    • iconOceanBase Admin Tool
    • iconOceanBase Loader and Dumper
    • iconOceanBase Deployer
    • iconKubernetes operator for OceanBase
    • iconOceanBase Diagnostic Tool
    • iconOceanBase Binlog Service
    • Connectors and Middleware
    • iconOceanBase Database Proxy
    • iconEmbedded SQL in C for OceanBase
    • iconOceanBase Call Interface
    • iconOceanBase Connector/C
    • iconOceanBase Connector/J
    • iconOceanBase Connector/ODBC
    • iconOceanBase Connector/NET
icon

OceanBase Database

SQL - V4.2.5

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogLive DemosTraining & CertificationTicket
    Company
    About OceanBaseTrust CenterLegalPartnerContact Us
    Follow Us

    © OceanBase 2026. All rights reserved

    Cloud Service AgreementPrivacy PolicySecurity
    Contact Us
    Document Feedback
    1. Documentation Center
    2. OceanBase Database
    3. SQL
    4. V4.2.5
    iconOceanBase Database
    SQL - V 4.2.5
    Databases
    • OceanBase Database
    • OceanBase Cloud
    • OceanBase Tugraph
    • Interactive Tutorials
    • OceanBase Best Practices
    Tools
    • OceanBase Cloud Platform
    • OceanBase Migration Service
    • OceanBase Developer Center
    • OceanBase Migration Assessment
    • OceanBase Admin Tool
    • OceanBase Loader and Dumper
    • OceanBase Deployer
    • Kubernetes operator for OceanBase
    • OceanBase Diagnostic Tool
    • OceanBase Binlog Service
    Connectors and Middleware
    • OceanBase Database Proxy
    • Embedded SQL in C for OceanBase
    • OceanBase Call Interface
    • OceanBase Connector/C
    • OceanBase Connector/J
    • OceanBase Connector/ODBC
    • OceanBase Connector/NET
    SQL
    KV
    • V 4.6.0
    • V 4.4.2
    • V 4.3.5
    • V 4.3.3
    • V 4.3.1
    • V 4.3.0
    • V 4.2.5
    • V 4.2.2
    • V 4.2.1
    • V 4.2.0
    • V 4.1.0
    • V 4.0.0
    • V 3.1.4 and earlier

    Use arithmetic operators in queries

    Last Updated:2026-04-09 09:38:52  Updated
    Share
    What is on this page
    Examples

    folded

    Share

    This topic provides specific examples on how to use arithmetic operators in queries.

    Common arithmetic operators used in queries include addition (+), subtraction (-), multiplication (*), division (/), negation (-), and modulus (MOD). These operators can be used on columns of numeric data types.

    Examples

    Query the number and price of commodities purchased by customers who meet the specified conditions. The product of the number and the price is the total payment of each commodity. You can add the t2.ol_quantity * t3.i_price column with the alias item_sum_price to the SELECT list.

    1. Create a table named cust.

      obclient> CREATE TABLE cust (
                  c_id        NUMBER,
                  c_first     VARCHAR2(20),
                  c_last      VARCHAR2(20),
                  c_credit    NUMBER(10, 2)
            );
      Query OK, 0 rows affected
      
    2. Create a table named ordr.

      obclient> CREATE TABLE ordr (
                  o_id         NUMBER,
                  o_ol_cnt     NUMBER,
                  o_entry_d    DATE
                );
      Query OK, 0 rows affected
      
    3. Create a table named item.

      obclient> CREATE TABLE item (
                  i_id           NUMBER,
                  i_name       VARCHAR2(20),
                  i_price       NUMBER(10, 2)
                  );
      Query OK, 0 rows affected
      
    4. Insert data into the cust table.

      obclient> INSERT INTO cust VALUES(101,'Ann','Smith',16.10),
                (102,'Madeleine','Johnson',23.00),
                (103,'Michael','Brown',9.05);
      Query OK, 3 rows affected
      Records: 3  Duplicates: 0  Warnings: 0
      
    5. Insert data into the ordr table.

      obclient> INSERT INTO ordr VALUES(102,400,date'2020-01-23'),
                (103,400,date'2020-01-23'),(104,300,date'2020-09-18'),
                (105,100,date'2020-07-01');
      Query OK, 4 rows affected
      Records: 4  Duplicates: 0  Warnings: 0
      
    6. Insert data into the item table.

      obclient> INSERT INTO item VALUES(102,'Apple','12.9'),
                (103,'Banana','10.2'),(105,'Pear','9.8');
      Query OK, 3 rows affected
      Records: 3  Duplicates: 0  Warnings: 0
      
    7. Query the number and price of commodities purchased by customers who meet the specified conditions.

      obclient> SELECT t1.c_first, t1.c_last, t1.c_credit, t2.o_ol_cnt * t3.i_price item_sum_price, t2.o_entry_d, t3.i_name, t3.i_price
                FROM cust t1
                JOIN ordr t2 ON (t1.c_id=t2.o_id)
                JOIN item t3 ON (t2.o_id=t3.i_id)
                ORDER BY t1.c_id, t2.o_id;
      +-----------+---------+----------+----------------+-----------+--------+---------+
      | C_FIRST   | C_LAST  | C_CREDIT | ITEM_SUM_PRICE | O_ENTRY_D | I_NAME | I_PRICE |
      +-----------+---------+----------+----------------+-----------+--------+---------+
      | Madeleine | Johnson |       23 |           5160 | 23-JAN-20 | Apple  |    12.9 |
      | Michael   | Brown   |     9.05 |           4080 | 23-JAN-20 | Banana |    10.2 |
      +-----------+---------+----------+----------------+-----------+--------+---------+
      2 rows in set
      

    Previous topic

    Lateral derived table
    Last

    Next topic

    Use numerical functions in queries
    Next
    What is on this page
    Examples