Oracle:将关联数组传递到嵌套表,以便在 C# 中的 SQL 语句中使用
本文关键字:中的 SQL 语句 数组 关联 嵌套 Oracle | 更新日期: 2023-09-27 18:35:15
我正在尝试将数字数组传递给预言机存储过程,以便我可以批量处理。 我必须传入关联数组,然后用内容填充嵌套表。 有没有更好的方法将数字数组或 varchar2 传递给预言机中的存储过程? 我这样做对吗?:)
我也在下面查看了临时表和管道函数作为这种工作方法的替代方案。
create or replace type t_number_table as table of number;
create or replace package numberarray_pkg
as
type t_numbers is table of number index by pls_integer;
type t_cursor is ref cursor;
procedure passarray(
paymentids in t_numbers,
io_cursor in out t_cursor);
end numberarray_pkg;
/
create or replace package body numberarray_pkg
as
procedure passarray(paymentids in t_numbers, io_cursor in out t_cursor) as
v_number_table t_number_table;
v_cursor t_cursor;
begin
v_number_table := t_number_table();
v_number_table.extend(paymentids.count);
for i in 1 .. paymentids.count loop
v_number_table(i) := paymentids(i);
end loop;
open v_cursor for
select column_value from table(v_number_table);
io_cursor := v_cursor;
end passarray;
end numberarray_pkg;
/
在主体创建脚本中,您必须声明一个默认变量,如下所示:
type t_numbers is table of number index by pls_integer;
nullNumber t_numbers;
在程序的规范中:
procedure passarray(
paymentids in t_numbers default nullNumber,
io_cursor in out t_cursor);
在代码中,仅当数组至少有一个值时,才必须将集合作为数组(重要)传递。