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

    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.4.2
    iconOceanBase Database
    SQL - V 4.4.2
    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

    Number format models

    Last Updated:2026-04-02 06:23:58  Updated
    Share
    What is on this page
    Number format models in functions
    Elements of a numeric format model
    Number format elements
    Example of element formatting
    Examples

    folded

    Share

    Number format models specify the format of fixed-point and floating-point numbers stored in the database. When you need to convert the values of the NUMBER, BINARY_FLOAT, or BINARY_DOUBLE data types in an SQL statement to the VARCHAR2 data type, you can use the number format models in the function.

    Number format models in functions

    You can use number format models in the following functions:

    • When NUMBER, BINARY_FLOAT, or BINARY_DOUBLE appears in an expression, condition, SQL function, or SQL statement, you can use the parameters of the TO_CHAR function to specify the format of these values when converting them to the VARCHAR2 data type.

    • When CHAR or VARCHAR2 appears in an expression, condition, SQL function, or SQL statement, you can use the parameters of the TO_NUMBER function (excluding NLS_NUMERIC_CHARACTERS) to specify the format of these values when converting them to the NUMBER data type.

    • When CHAR or VARCHAR2 appears in an expression, condition, SQL function, or SQL statement, you can use the parameters of the TO_BINARY_FLOAT and TO_BINARY_DOUBLE functions to specify the format of these values when converting them to the BINARY_FLOAT or BINARY_DOUBLE data types.

    Number format models round the values and retain the specified number of significant digits. If the number of decimal places in a value exceeds the number of decimal places specified in the format, the value is replaced with a #.

    If a positive NUMBER value is too large to be represented in the specified format, it is replaced with the infinity symbol (~). If a negative NUMBER value is too small to be represented in the specified format, it is replaced with the negative infinity symbol (-~).

    Elements of a numeric format model

    Number format elements

    A number format model consists of one or more number format elements. Negative return values automatically include a leading minus sign, and positive values automatically include a leading space, unless the format model includes elements such as MI, S, or PR that indicate the sign of a number.

    The following table lists the elements included in a number format model and their specific usage.

    Element
    Example
    Description
    , (comma) 9,999 Returns a comma at the specified position. You can specify multiple commas in a number format model. Limitations: A comma element cannot appear at the beginning of a number format model. In a number format model, a comma cannot appear to the right of a decimal point or a period.
    . (decimal point) 99.99 Returns a decimal point at the specified position. Limitation: You can specify only one decimal point in a number format model.
    $ $9999 Returns the value with a leading dollar sign.
    0 0999 9990 Returns leading zeros. Leading zeros are usually represented as spaces, except when the formatted value is 0, in which case leading zeros are represented as the character 0. Returns trailing zeros.
    9 9999 Returns a result with the specified number of digits. If the formatted value is a positive number, the result contains leading spaces. Otherwise, the result contains a leading negative sign.
    B B9999 Returns a space when the result is zero.
    C C999 Returns the ISO currency symbol (the value specified by the NLS_ISO_CURRENCY parameter) at the specified position.
    D 99D99 Functions the same as ".", but can appear only once. The difference is that this element uses the default value of the NLS_NUMERIC_CHARACTER parameter.
    EEEE 9.9EEEE Returns the value in scientific notation.
    G 9G999 The behavior is the same as the behavior of the . element, except that this element uses the default value of the NLS_NUMERIC_CHARACTER parameter.
    L L999 Returns the local currency symbol at the specified position. This element uses the value of the NLS_CURRENCY parameter.
    Mi 9999MI Returns a negative value with a trailing minus sign (-) and a positive value with a trailing space. Limitation: The Mi format element can appear only at the end of a numeric format model.
    PR 9999PR Returns a negative value within angle brackets (<>) and a positive value with leading and trailing spaces. Limitation: The PR format element can appear only at the end of a numeric format model.
    RN(rn) RN rn Returns the value in uppercase Roman numerals or lowercase Roman numerals. Limitation: The value can be an integer between 1 and 3999.
    S S9999 9999S
    • Returns a negative value with a leading minus sign (-).
    • Returns a positive value with a leading plus sign (+).
    • Returns a negative value with a trailing minus sign (-).
    • Returns a positive value with a trailing plus sign (+).
    Limitation: The S format element can appear only at the first or last position of a numeric format model.
    TM TME TM9 The default value is TM9. If the output does not exceed 64 characters, the number is returned with a fixed symbol. If the output exceeds 64 characters, the number is returned in scientific notation. When the number has more than 64 digits, the output of TM9 is the same as the output of TME.
    U U9999 Returns the euro (or other) dual currency symbol at the specified position, determined by the current value of the NLS_dual_currency parameter.
    V(v) 999V99 Returns a value multiplied by 10n (rounded if necessary), where n is the number of 9s following the V element.
    X(x) XXXX xxxx Returns a hexadecimal value with the specified number of digits. If the specified number is not an integer, it is rounded to the nearest integer. Limitations:
    • This element accepts only positive values or 0. Negative values return an error.
    • You can precede this element only with 0 (to return leading zeros) or FM. Any other element returns an error. If you use X without specifying 0 or FM, the returned value always has a leading space.
    FM(fm) FM999 Removes leading spaces.

    Example of element formatting

    The following table shows the conversion results when you execute the SQL command SELECT TO_CHAR(number, 'fmt') FROM DUAL; for different numbers with the format element parameter fmt. If you omit the format model parameter fmt, the number is converted to a VARCHAR2 of sufficient length to retain all its significant digits.

    Number
    'fmt'
    Result
    0 99.99 '.00'
    +0.1 99.99 '.10'
    -0.2 99.99 '-.20'
    0 90.99 '0.00'
    +0.1 90.99 '0.10'
    -0.2 90.99 '-0.20'
    0 9999 '0'
    1 9999 '1'
    +123.456 999.999 '123.456'
    -123.456 999.999 '-123.456'

    Examples

    • Convert the value 0 to a value with a decimal point and two significant digits after the decimal point.

      obclient> SELECT TO_CHAR(0, '99.99') FROM DUAL;
      +--------------------+
      | TO_CHAR(0,'99.99') |
      +--------------------+
      |    .00             |
      +--------------------+
      1 row in set
      
    • Omit the fmt parameter and retain all significant digits of the value.

      obclient> SELECT TO_CHAR(123.456) FROM DUAL;
      +------------------+
      | TO_CHAR(123.456) |
      +------------------+
      | 123.456          |
      +------------------+
      1 row in set
      
    • If the result of TO_CHAR exceeds 40 bytes or the input parameter is of type BINARY_DOUBLE or BINARY_FLOAT, the result is converted to scientific notation.

      obclient> SELECT TO_CHAR(12355555555555555555555555555555555555555555555555) FROM DUAL;
      +-------------------------------------------------------------+
      | TO_CHAR(12355555555555555555555555555555555555555555555555) |
      +-------------------------------------------------------------+
      | 1.2355555555555555555555555555555556E+49                    |
      +-------------------------------------------------------------+
      1 row in set
      

    Previous topic

    Overview
    Last

    Next topic

    Datetime format models
    Next
    What is on this page
    Number format models in functions
    Elements of a numeric format model
    Number format elements
    Example of element formatting
    Examples