Meet OceanBase AI Database, the unified database for operational data, real-time analytics, and AI. Explore ->

Meet OceanBase AI Database, the unified database for operational data, real-time analytics, and AI. Explore ->

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

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogWhite PaperLive 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.1
    iconOceanBase Database
    SQL - V 4.2.1
    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

    RAW data type

    Last Updated:2026-04-28 09:23:26  Updated
    Share
    What is on this page
    Considerations
    Implicit conversion rules
    Explicit conversion mode
    Examples

    folded

    Share

    The RAW data type is a length-variable data type. The binary data flows can be transmitted between databases with different character sets and between database servers and clients with different character sets, without character set conversion. This topic describes the syntax, parameters, and considerations of the RAW data type.

    The RAW data type stores binary data or strings such as images or audios.

    The SQL syntax of the RAW data type is as follows:

    RAW(length)
    

    The length parameter specifies the length, in bytes. If you use this parameter to specify the length of a table column in a database, a maximum of 2,000 bytes can be stored in the column. If you use this parameter to specify the length of a PL variable, a maximum of 32,767 bytes can be stored in the variable.

    Considerations

    Implicit conversion rules

    When OceanBase Database implicitly converts RAW type data to character type data such as CHAR or VARCHAR2, each character corresponds to a hexadecimal number that is represented by four consecutive bits of the RAW type, namely, 0-9 and A-F or a-f. For example, the binary bits 11001011 (one byte) of the RAW data type is converted to 'CB' (two bytes) of the character type.

    When OceanBase Database implicitly converts character type data to RAW type data, the hexadecimal number represented by each character in a string is converted to four digits. For example, the string 'AB' is converted to 0XAB (10101011).

    Notice

    If any input character is not a hexadecimal number (0-9 and A-F or a-f), an error is returned. If the number of characters is odd, RAW type data starts with 0 until the RAW type data is filled with bytes. For example, when OceanBase Database converts the string 'ABC' to RAW type data, the string is converted to 0x0ABC, with 0x0A taking one byte and 0xBC taking one byte.

    Explicit conversion mode

    SQL functions RAWTOHEX() and HEXTORAW() perform an explicit conversion equivalent to the above implicit conversion. You can use functions in PL system packages UTL_RAW and UTL_I18N to convert data between RAW and character data types.

    The SQL function HEXTORAW() converts data in a string to a hexadecimal number. The SQL function UTL_RAW.CAST_TO_RAW([VARCHAR2]) stores the ASCII code of each character in the string to fields of the RAW type. For example, convert 051 to 303531.

    By implicitly calling the SQL function RAWTOHEX(), OceanBase Database can convert a hexadecimal string of the RAW type to a hexadecimal string of the VARCHAR type.

    The following table lists functions related to the RAW data type.

    Function
    Description
    HEXTORAW() Converts data in a string to a hexadecimal string. Each two characters in the string represent one byte of the RAW data.
    RAWTOHEX(rawvalue) Converts the RAW value rawvalue into a hexadecimal string. Each byte of rawvalue is converted into a 2-byte string.
    UTL_RAW.CAST_TO_RAW([VARCHAR2]) Keeps the stored data unchanged and changes only the data type from VARCHAR2 to RAW.
    UTL_RAW.CAST_TO_VARCHAR2([RAW]) Keeps the stored data unchanged and changes only the data type from RAW to VARCHAR2.
    UTL_RAW.BIT_OR() UTL_RAW.BIT_AND() UTL_RAW.BIT_XOR() Performs bitwise operations.

    Examples

    • Declare RAW data in the test_raw table and insert a piece of data into the table.

      obclient> CREATE TABLE test_raw (col1 RAW(10));
      Query OK, 0 rows affected
      
      obclient> INSERT INTO test_raw VALUES (UTL_RAW.CAST_TO_RAW('1234567890'));
      Query OK, 1 row affected
      
      obclient> SELECT UTL_RAW.CAST_TO_VARCHAR2(col1) FROM test_raw;
      +--------------------------------+
      | UTL_RAW.CAST_TO_VARCHAR2(COL1) |
      +--------------------------------+
      | 1234567890                     |
      +--------------------------------+
      1 row in set
      
    • Insert two pieces of data into the raw_test01 table and use the conversion function.

      obclient> CREATE TABLE raw_test01 (id NUMBER, raw_date RAW(10));
      Query OK, 0 rows affected
      
      obclient> INSERT INTO raw_test01 VALUES  (1, HEXTORAW('ff'));
      Query OK, 1 row affected
      
      obclient> INSERT INTO raw_test01 VALUES  (2, UTL_RAW.CAST_TO_RAW('051'));
      Query OK, 1 row affected
      
      obclient> SELECT * FROM raw_test01;
      +------+----------+
      | ID   | RAW_DATE |
      +------+----------+
      |    1 | FF       |
      |    2 | 303531   |
      +------+----------+
      2 rows in set
      

    Previous topic

    Calculation of dates, timestamps, and intervals
    Last

    Next topic

    Overview
    Next
    What is on this page
    Considerations
    Implicit conversion rules
    Explicit conversion mode
    Examples