---
title: INSERT IGNORE with global index 不支持-OceanBase数据库使用指南
description: 了解OceanBase数据库在实际应用中关于INSERT IGNORE with global index 不支持相关的常见问题和使用技巧，帮助您快速解决INSERT IGNORE with global index 不支持的难题。
---
切换语言

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

划线反馈

# INSERT IGNORE with global index 不支持

更新时间：2026-05-28 02:06

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

Oracle 租户不支持 INSERT IGNORE 语法。

## 问题现象

使用 INSERT IGNORE 语句插入时报错。

```shell
obclient [gtx_test]> insert ignore into  gtx_tb1 values(3,3,'3');
ERROR 1235 (0A000): ignore with global index not supported

```

## 问题原因

MySQL 租户支持使用 INSERT IGNORE 来忽略 INSERT 过程发生的错误（比如主角冲突等），让 INSERT 语句可以继续执行，并返回一个"正确"的返回码（ret_code）。比如，在一次性插入多条记录时，可以使用 INSERT IGNORE 来忽略其中某些记录的插入失败，让其他记录得以插入成功。 但是，当表中存在 Global 索引时，INSERT IGNORE 功能不被支持。

测试示例如下。

1. 创建测试表 gtx_tb1，设置主键为 c1，并插入2 条记录。

   ```shell
   obclient [gtx_test]> create table gtx_tb1 (c1 integer primary key, c2 integer, c3 varchar(100)) partition by hash(c1) partitions 9;
   Query OK, 0 rows affected (0.067 sec)

   ```

   ```shell
   obclient [gtx_test]> insert into gtx_tb1 values(1,1,'1'),(2,2,'2');
   Query OK, 1 row affected (0.008 sec)

   ```
 2. 查询测试表内容。

   ```shell
   obclient [gtx_test]> select * from gtx_tb1;

   ```

   输出结果如下。

   ```shell
   +----+------+------+
   | c1 | c2   | c3   |
   +----+------+------+
   |  1 |    1 | 1    |
   |  2 |    2 | 2    |
   +----+------+------+
   2 rows in set (0.019 sec)

   ```
 3. 再插入 2 条记录：(2,2,'x'),(3,3,'3')。其中，(2,2,'x') 会导致主键冲突，不论是否使用 IGNORE, 都不会插入成功。

   ```shell
   obclient [gtx_test]> insert into  gtx_tb1 values(2,2,'x'),(3,3,'3');
   ERROR 1062 (23000): Duplicate entry '2' for key 'PRIMARY'

   ```

   ```shell
   obclient [gtx_test]> insert ignore into  gtx_tb1 values(2,2,'x'),(3,3,'3');
   Query OK, 1 row affected (0.005 sec)

   ```
 4. 再次查询测试表内容。

   ```

   输出结果如下。

   ```shell
   +----+------+------+
   | c1 | c2   | c3   |
   +----+------+------+
   |  2 |    2 | 2    |
   |  1 |    1 | 1    |
   |  3 |    3 | 3    |
   +----+------+------+
   3 rows in set (0.003 sec)

   ```
 5. 查看 INSERT 语句的返回码，INSERT IGNORE 忽略了主键冲突的报错。

   ```shell
   obclient [gtx_test]> select query_sql,ret_code from oceanbase.gv$sql_audit where query_sql like 'insert%gtx_tb1%' order by request_time desc limit 10;

   ```

   输出结果如下。

   ```shell
   +-------------------------------------------------------+----------+
   | query_sql                                             | ret_code |
   +-------------------------------------------------------+----------+
   | insert ignore into  gtx_tb1 values(2,3,'x'),(3,3,'3') |        0 |
   | insert into  gtx_tb1 values(2,2,'x'),(3,3,'3')        |    -5024 |
   | insert into  gtx_tb1 values(1,1,'1'),(2,2,'2')        |        0 |
   +-------------------------------------------------------+----------+

   ```
 6. 创建 Global 索引，再次使用 INSERT IGNORE 时报错。

   ```shell
   obclient [gtx_test]> create index gtx_tb1_ix1 on gtx_tb1(c2) global;
   Query OK, 0 rows affected (0.872 sec)

   ```

   ```shell
   obclient [gtx_test]> insert ignore into  gtx_tb1 values(2,3,'x'),(3,3,'3');
   ERROR 1235 (0A000): ignore with global index not supported

   ```

   ```shell
   obclient [gtx_test]> insert ignore into  gtx_tb1 values(4,4,'4');
   ERROR 1235 (0A000): ignore with global index not supported

   ```

## 适用版本

OceanBase 数据库所有版本。

## 解决方式

当表中存在 Global 索引时，INSERT IGNORE 语句不被支持。需要应用程序来保证 INSERT 语句正确，避免出现错误。

上一篇

[OceanBase 数据库执行超长 insert all into 报错 -4002](https://www.oceanbase.com/knowledge-base/oceanbase-database-1000000000209993)

下一篇

[Truncate 后执行 INSERT 发生数据丢失](https://www.oceanbase.com/knowledge-base/oceanbase-database-1000000000207751) ![有帮助](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) 咨询热线
