From 63fb590a48bcc757695adf2036d40a574af466dd Mon Sep 17 00:00:00 2001 From: He Bomou Date: Tue, 15 Apr 2025 11:21:03 +0800 Subject: [PATCH] =?UTF-8?q?fix(IBZM5X):=20=E8=A1=A5=E5=85=85=E6=95=B0?= =?UTF-8?q?=E7=BB=84=E4=BD=BF=E7=94=A8=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SQLReference/\346\225\260\347\273\204.md" | 45 ++++++++++++++++++- .../SQLReference/\346\225\260\347\273\204.md" | 45 ++++++++++++++++++- 2 files changed, 88 insertions(+), 2 deletions(-) diff --git "a/content/docs-lite/zh/docs/SQLReference/\346\225\260\347\273\204.md" "b/content/docs-lite/zh/docs/SQLReference/\346\225\260\347\273\204.md" index 6b86a237d..c7bb66c6b 100644 --- "a/content/docs-lite/zh/docs/SQLReference/\346\225\260\347\273\204.md" +++ "b/content/docs-lite/zh/docs/SQLReference/\346\225\260\347\273\204.md" @@ -1,6 +1,6 @@ # 数组 -## 数组类型的使用 +## 特性说明 在使用数组之前,需要自定义一个数组类型。 @@ -32,3 +32,46 @@ openGauss支持使用圆括号来访问数组元素,且还支持一些特有 >存储过程中如果有DML语句(SELECT、UPDATE、INSERT、DELETE),DML语句推荐使用中括号来访问数组元素,使用小括号默认识别为数组访问,若数组不存在,则识别为函数表达式。 >存储过程中的table of类型、record类型、clob作为出入参、游标、raise info等对大于1GB的clob类型不支持。 +## 示例 + +```sql +-- 建表 +create table tbl (col integer); + +-- 该存储过程会向表中插入 1 到 10 的十条记录 +create or replace procedure insert_arr +as + -- 定义数组类型 + type int_arr is varray(10) of integer; + p_arr int_arr := int_arr(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); +begin + for i in 1..p_arr.count loop + insert into tbl values (p_arr(i)); + end loop; +end; +/ + +-- 调用存储过程 +call insert_arr(); + +-- 查表 +select * from tbl; +``` + +查表输出结果: + +```txt + col +----- + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 +(10 rows) +``` diff --git "a/content/zh/docs/SQLReference/\346\225\260\347\273\204.md" "b/content/zh/docs/SQLReference/\346\225\260\347\273\204.md" index 8db3a7b47..bc4c457a0 100644 --- "a/content/zh/docs/SQLReference/\346\225\260\347\273\204.md" +++ "b/content/zh/docs/SQLReference/\346\225\260\347\273\204.md" @@ -1,6 +1,6 @@ # 数组 -## 数组类型的使用 +## 特性说明 在使用数组之前,需要自定义一个数组类型。 @@ -31,3 +31,46 @@ openGauss支持使用圆括号来访问数组元素,且还支持一些特有 > >存储过程中的table of类型、record类型、clob作为出入参、游标、raise info等对大于1GB的clob类型不支持。 +## 示例 + +```sql +-- 建表 +create table tbl (col integer); + +-- 该存储过程会向表中插入 1 到 10 的十条记录 +create or replace procedure insert_arr +as + -- 定义数组类型 + type int_arr is varray(10) of integer; + p_arr int_arr := int_arr(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); +begin + for i in 1..p_arr.count loop + insert into tbl values (p_arr(i)); + end loop; +end; +/ + +-- 调用存储过程 +call insert_arr(); + +-- 查表 +select * from tbl; +``` + +查表输出结果: + +```txt + col +----- + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 +(10 rows) +``` -- Gitee