---
title: "数组输出函数 - OceanBase 数据库 V4.5.0 | OceanBase 文档中心"
description: 数组输出函数 数组输出函数用于选择数组数据输出形式，如以字符串的形式依次输出数组数据的每一个元素，并以逗号隔开。OceanBase 数据库当前所支持的数组输出函数包括 array_to_string() 。 array_to_string array_to_string() 函数将数组转换为字符串。具体而言，即根据指…
---
切换语言

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

文档反馈![](https://mdn.alipayobjects.com/huamei_22khvb/afts/img/A*P8CuR4UJ_FkAAAAAAAAAAAAADiGDAQ/original) OceanBase 数据库分布式版 - V 4.5.0

# 数组输出函数

更新时间：2026-04-12 12:08:20

[编辑](https://github.com/oceanbase/oceanbase-doc/edit/V4.5.0/zh-CN/700.reference/500.sql-reference/100.sql-syntax/200.common-tenant-of-mysql-mode/400.functions-of-mysql-mode/950.array-functions-of-mysql-mode/500.array-output-functions-of-mysql-mode.md)  

数组输出函数用于选择数组数据输出形式，如以字符串的形式依次输出数组数据的每一个元素，并以逗号隔开。OceanBase 数据库当前所支持的数组输出函数包括 `array_to_string()`。

## array_to_string

`array_to_string()` 函数将数组转换为字符串。具体而言，即根据指定的分隔符和空元素符将数组中的所有基础元素打印成字符串。如果数组为嵌套数组，则递归打印其非空子数组。与 [string_to_array()](https://www.oceanbase.com/docs/common-oceanbase-database-cn-1000000004480636) 不完全互为逆函数。语法如下：

```sql
array_to_string(arr1, delimiter[, null_str])

```

输入参数说明如下：

- `arr1` 传入的类型必须是一个数组类型。
 - `delimiter` 分隔符，支持字符类型，包含 Char、Varchar 类型。
 - `null_str`（可选） 空元素符，支持字符类型，包含 Char、Varchar 类型。若不指定，则不打印 NULL 元素及其相应的分隔符。

返回结果为 Text 类型的字符串。

示例如下：

```sql
SELECT array_to_string([1,2,NULL,3], '-', 'N');
+-----------------------------------------+
| array_to_string([1,2,NULL,3], '-', 'N') |
+-----------------------------------------+
| 1-2-N-3                                 |
+-----------------------------------------+
1 row in set

```

```sql
SELECT array_to_string([1,2,NULL,3], 'and');
+--------------------------------------+
| array_to_string([1,2,NULL,3], 'and') |
+--------------------------------------+
| 1and2and3                            |
+--------------------------------------+
1 row in set

```

```sql
SELECT array_to_string([["hello", "world"], ["hi", "what"]], '-');
+------------------------------------------------------------+
| array_to_string([["hello", "world"], ["hi", "what"]], '-') |
+------------------------------------------------------------+
| hello-world-hi-what                                        |
+------------------------------------------------------------+
1 row in set

```

```sql
SELECT array_to_string([["hello", "world"], ["hi", "what"], NULL], '-', 'N');
+-----------------------------------------------------------------------+
| array_to_string([["hello", "world"], ["hi", "what"], NULL], '-', 'N') |
+-----------------------------------------------------------------------+
| hello-world-hi-what-N                                                 |
+-----------------------------------------------------------------------+
1 row in set

```

 上一篇 下一篇 ![有帮助](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) 咨询热线
