---
title: OceanBase 数据库 BLOB 列无法直接创建索引-OceanBase数据库使用指南
description: 了解OceanBase数据库在实际应用中关于OceanBase 数据库 BLOB 列无法直接创建索引相关的常见问题和使用技巧，帮助您快速解决OceanBase 数据库 BLOB 列无法直接创建索引的难题。
---
切换语言

- 中文站 - 简体中文
- International - English
- 日本站 - 日本語

划线反馈

# OceanBase 数据库 BLOB 列无法直接创建索引

更新时间：2026-05-22 08:56

适用版本： V2.2.x、V3.1.x、V3.2.x 内容类型：Troubleshoot  

## 问题描述

对于 OceanBase 数据库的 Oracle 模式和 MySQL 模式都存在这个问题，也即都不能在含有 BLOB 列的字段上直接建立索引。具体报错如下。

1. MySQL 模式下在 BLOB 列上创建本地索引、全局索引均报错。

   ```shell
   obclient [test]> create table t1(id int primary key,r1 blob);
   Query OK, 0 rows affected (0.601 sec)

   ```

   ```shell
   obclient [test]> create index idx_r1 on t1(r1) local;
   ERROR 1167 (42000): The used storage engine can't index column 'r1'

   ```

   ```shell
   obclient [test]> create index gdx_r1 on t1(r1) global;
   ERROR 1167 (42000): The used storage engine can't index column 'r1'

   ```
 2. Oracle 模式下在 BLOB 列上创建本地索引、全局索引均报错。

   ```shell
   obclient [SYS]> create table t1(id int primary key, r1 blob);
   Query OK, 0 rows affected (0.197 sec)

   ```

   ```shell
   obclient [SYS]> create index idx_r1 on t1(r1);
   ORA-02329: column 'R1' of datatype string cannot be unique or a primary key

   ```

   ```shell
   obclient [SYS]> create index gdx_r1 on t1(r1) global;
   ORA-02329: column 'R1' of datatype string cannot be unique or a primary key

   ```

## 适用版本

OceanBase 数据库 V2.x 和 V3.x 版本。

## 问题原因

数据库目前版本功能限制。

## 解决方法

由于 BLOB 字段一般存储的数据都很大，不能直接全字段建立索引，需要变通的建立前缀索引来实现原先的建索引需求。

1. MySQL 模式解决方法为建立前缀索引。对于本地索引和全局索引均有效。

   ```shell
   obclient [test]> create index idx_r1 on t1(r1(100)) local;
   Query OK, 0 rows affected (1.498 sec)

   ```

   ```shell
   obclient [test]> create index gdx_r1 on t1(r1(100)) global;
   Query OK, 0 rows affected (1.440 sec)

   ```
 2. Oracle 模式解决方法为建立函数索引。对于本地索引和全局索引均有效。

   ```shell
   obclient [SYS]> create index idx_r1 on t1(substr(r1,1,100));
   Query OK, 0 rows affected (1.012 sec)

   ```

   ```shell
   obclient [SYS]> create index gdx_r1 on t1(substr(r1,1,100));
   Query OK, 0 rows affected (0.840 sec)

   ```

上一篇

[创建索引报长度超过 16KB 的错误](https://www.oceanbase.com/knowledge-base/oceanbase-database-1000000000207734)

下一篇

[OceanBase 数据库 V4.0 中创建索引和 V3.2.3 中相比，耗时长多了](https://www.oceanbase.com/knowledge-base/oceanbase-database-1000000000207736) ![有帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*y6ocSqN8cqsAAAAAAAAAAAAAARQnAQ)![无帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*BG9IQJyLHF8AAAAAAAAAAAAAARQnAQ)![反馈](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*eTWdQKCRKHwAAAAAAAAAAAAAARQnAQ)[AI](https://www.oceanbase.com/obi) 咨询热线
