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.6.0

    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.6.0
    iconOceanBase Database
    SQL - V 4.6.0
    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

    STDDEV

    Last Updated:2026-05-07 11:26:25  Updated
    share
    What is on this page
    Purpose
    Syntax
    Parameters
    Return type
    Examples
    Example of an aggregate function
    Example of an analytic function

    folded

    share

    Purpose

    This function calculates the standard deviation of a set of numeric data. The difference between this function and the STDDEV_SAMP function is that the STDDEV function returns 0 when only one row of data is provided, while the STDDEV_SAMP function returns NULL. In OceanBase Database, the standard deviation value is the arithmetic square root of the variance calculated by the VARIANCE function. It can be used as an aggregate or analytic function.

    Note

    • When used as an analytic function, you must use the OVER clause to define the window for calculation. It calculates the standard deviation for a set of rows and returns multiple values.
    • When used as an aggregate function, it aggregates the standard deviation for a set of rows and returns only one value. In this case, the OVER clause is not required.

    Syntax

    STDDEV([ DISTINCT | UNIQUE | ALL ] expr) [ OVER (analytic_clause) ]
    

    Parameters

    Parameter
    Description
    DISTINCT | UNIQUE | ALL Specifies whether to remove duplicates. This is an optional parameter, with a default value of ALL.
    • ALL: All numeric columns.
    • DISTINCT: A keyword indicating that the standard deviation of unique values is to be calculated.
    • UNIQUE: A keyword indicating that the standard deviation of unique values is to be calculated.
    expr A numeric value or a value that can be converted to a numeric value.
    OVER Specifies the OVER clause to define the window for calculation. For more information, see Analytic functions.

    Notice

    If you specify the DISTINCT or UNIQUE keyword, the analytic_clause cannot contain the order_by_clause or windowing_clause.

    Return type

    The function returns a value of the NUMBER type.

    Examples

    Assume that the employees table has been created.

    obclient> SELECT * FROM employees;
    +---------------+-----------+------------+--------+
    | DEPARTMENT_ID | LAST_NAME | HIREDATE   | SALARY |
    +---------------+-----------+------------+--------+
    |            30 | Raphaely  | 2017-07-01 |   1700 |
    |            30 | De Haan   | 2018-05-01 |  11000 |
    |            40 | Errazuriz | 2017-07-21 |   1400 |
    |            50 | Hartstein | 2019-10-05 |  14000 |
    |            50 | Raphaely  | 2017-07-22 |   1700 |
    |            50 | Weiss     | 2019-10-05 |  13500 |
    |            90 | Russell   | 2019-07-11 |  13000 |
    |            90 | Partners  | 2018-12-01 |  14000 |
    +---------------+-----------+------------+--------+
    8 rows in set
    

    Example of an aggregate function

    Calculate the standard deviation of the salary column.

    obclient> SELECT STDDEV(salary) FROM employees;
    +-------------------------------------------+
    | STDDEV(SALARY)                            |
    +-------------------------------------------+
    | 6026.474330580265330900400184969999384459 |
    +-------------------------------------------+
    1 row in set
    

    Example of an analytic function

    Sort the rows in ascending order by the hiredate column and calculate the cumulative standard deviation of the salary column.

    obclient> SELECT last_name,hiredate,salary,STDDEV(salary) OVER (ORDER BY hiredate) "StdDev"
              FROM employees;
    +-----------+------------+--------+-------------------------------------------+
    | LAST_NAME | HIREDATE   | SALARY | StdDev                                    |
    +-----------+------------+--------+-------------------------------------------+
    | Raphaely  | 2017-07-01 |   1700 |                                         0 |
    | Errazuriz | 2017-07-21 |   1400 |  212.132034355964257320253308631454711785 |
    | Raphaely  | 2017-07-22 |   1700 |  173.205080756887729352744634150587236694 |
    | De Haan   | 2018-05-01 |  11000 | 4702.127178203498995615489088200868644482 |
    | Partners  | 2018-12-01 |  14000 | 6064.899009876421676804205219406952308814 |
    | Russell   | 2019-07-11 |  13000 |  6138.94670661561181357873224397795992899 |
    | Hartstein | 2019-10-05 |  14000 | 6026.474330580265330900400184969999384459 |
    | Weiss     | 2019-10-05 |  13500 | 6026.474330580265330900400184969999384459 |
    +-----------+------------+--------+-------------------------------------------+
    8 rows in set
    

    Previous topic

    ROLLUP
    Last

    Next topic

    STDDEV_POP
    Next
    What is on this page
    Purpose
    Syntax
    Parameters
    Return type
    Examples
    Example of an aggregate function
    Example of an analytic function