---
title: 在执行 CTE 类 SQL 语句时出现 cte define column num does not match the select it 的原因和解决方法-OceanBase数据库使用指南
description: 了解OceanBase数据库在实际应用中关于在执行 CTE 类 SQL 语句时出现 cte define column num does not match the select it 的原因和解决方法相关的常见问题和使用技巧，帮助您快速解决在执行 CTE 类 SQL 语句时出现 cte define column num does not match the select it 的原因和解决方法的难题。
---
切换语言

- 简体中文
- English

划线反馈

# 在执行 CTE 类 SQL 语句时出现 cte define column num does not match the select it 的原因和解决方法

更新时间：2026-05-29 08:46

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

## 问题现象

在 OceanBase 集群执行与 CTE 相关的 SQL 语句时，出现如下异常。

```shell
ERROR 5740 (HY000): number of WITH clause column names does not match number of elements in select list

```

伴随如下关键日志信息。

```shell
[2024-07-11 14:16:28.201366] WARN  [SQL.RESV] add_fake_schema (ob_select_resolver.cpp:3535) [53072][0][xxxxx-xxxxx-xxxxx-xxxxx] [lt=11] [dc=0] cte define column num does not match the select item nums from left query(ret=-5740)

```

## 问题原因

该问题是由于 OceanBase 内部对某些 CTE 行为做了限制导致，属于兼容性问题，触发该问题需要满足 2 点：

1. CTE 表引用了自身 CTE 是递归的这种场景。
 2. CTE 语句中使用了 View（内含 CTE）的场景。

## 问题的风险及影响

SQL 执行失败。

## 影响租户

影响 OceanBase 数据库中的 SYS 租户和 Oracle 租户以及 MySQL 租户。

## 适用版本

OceanBase 数据库 V3.x 版本。

## 解决方法及规避方式

- 改写 SQL。
 - 使用 OceanBase 数据库 V4.x 集群。

Previous

[绑定 outline 后，原有查询里的 hint 都会被忽略](https://www.oceanbase.com/knowledge-base/oceanbase-database-1000000002342479)

Next

[MySQL 租户大小写敏感时的 Hint 使用说明](https://www.oceanbase.com/knowledge-base/oceanbase-database-1000000003894617) ![有帮助](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) 咨询热线
