SQL 嵌套 table 类型的默认集合类型

default collection type for SQL nested table type

我有一个 Oracle 类型,它是 table 个数字:

CREATE OR REPLACE TYPE t_number AS TABLE OF number;

现在我想在过程的输入参数中使用该类型,如下所示:

CREATE OR REPLACE PROCEDURE proc1 (pt_numbers_in IN t_number)...

如果参数为空,如何设置默认值?使用 PL/SQL 集合类型,我知道如何创建一个空集合(例如,在包规范中)并将其用作默认值。我必须在这里做同样的事情,还是有更好的方法来使用 SQL 类型的默认变量?我想要这样的东西:

CREATE OR REPLACE PROCEDURE proc1 (pt_numbers_in IN t_number DEFAULT NULL)...

我是 运行 11.2.0.4.

来自 How to Initialize Variables

的类似内容
DECLARE
   t_number_var t_number := t_number(5);  -- initialize
BEGIN
   IF t_number_var(1) IS NULL THEN 

How do I set a default value if the parameter is null?

您必须编写一些代码并检查集合是否是 null 集合,如果是,则对其进行初始化。

如果 "default" 值是指 "I want this parameter to be optional",那么只需使用 default 子句来初始化集合,如下所示:

create or replace procedure proc1(
  p_numbers_in in t_number default t_number(1,2,3)
)
as
begin
  -- some useful code 
end;