Oracle PL/SQL - How to create a simple array variable?(Oracle PL/SQL - 如何创建一个简单的数组变量?)
问题描述
我想创建一个可在我的 PL/SQL 代码中使用的内存中数组变量.我在 Oracle PL/SQL 中找不到任何使用纯内存的集合,它们似乎都与表相关联.我希望在我的 PL/SQL(C# 语法)中做这样的事情:
I'd like to create an in-memory array variable that can be used in my PL/SQL code. I can't find any collections in Oracle PL/SQL that uses pure memory, they all seem to be associated with tables. I'm looking to do something like this in my PL/SQL (C# syntax):
string[] arrayvalues = new string[3] {"Matt", "Joanne", "Robert"};
甲骨文:9i
推荐答案
您可以将 VARRAY 用于固定大小的数组:
You can use VARRAY for a fixed-size array:
declare
type array_t is varray(3) of varchar2(10);
array array_t := array_t('Matt', 'Joanne', 'Robert');
begin
for i in 1..array.count loop
dbms_output.put_line(array(i));
end loop;
end;
对于无界数组或 TABLE:
Or TABLE for an unbounded array:
...
type array_t is table of varchar2(10);
...
这里的表"一词与数据库表无关,令人困惑.两种方法都创建内存数组.
The word "table" here has nothing to do with database tables, confusingly. Both methods create in-memory arrays.
使用其中任何一个,您都需要在添加元素之前初始化和扩展集合:
With either of these you need to both initialise and extend the collection before adding elements:
declare
type array_t is varray(3) of varchar2(10);
array array_t := array_t(); -- Initialise it
begin
for i in 1..3 loop
array.extend(); -- Extend it
array(i) := 'x';
end loop;
end;
第一个索引是 1 而不是 0.
The first index is 1 not 0.
这篇关于Oracle PL/SQL - 如何创建一个简单的数组变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Oracle PL/SQL - 如何创建一个简单的数组变量?


基础教程推荐
- 带更新的 sqlite CTE 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01