首先,它们的类型需要在过程外部声明,以便类型定义对过程外部的代码可见。您可以在 SQL 中声明类型
CREATE TYPE list_of_names_t
AS TABLE OF NUMBER;
或者你可以在 PL/SQL 中声明它
CREATE OR REPLACE PACKAGE types_package
AS
TYPE list_of_names_t
IS TABLE OF emp.emp_index%type;
END;
然后,您的过程将不得不使用并返回 SQL 类型
CREATE OR REPLACE PROCEDURE sample_procedure(
p_ignore_indexes OUT list_of_names_t
)
AS
BEGIN
-- Logic here which fills the values in the collection p_ignore_indexes
END;
或 PL/SQL 类型
CREATE OR REPLACE PROCEDURE sample_procedure(
p_ignore_indexes OUT types_package.list_of_names_t
)
AS
BEGIN
-- Logic here which fills the values in the collection p_ignore_indexes
END;
当然,如果您的代码的目的是返回一个集合,那么编写函数比编写过程更有意义
CREATE OR REPLACE FUNCTION sample_function
RETURN types_package.list_of_names_t
AS
ignore_indexes types_package.list_of_names_t;
BEGIN
-- Logic here which fills the values in the collection ignore_indexes
RETURN ignore_indexes;
END;
当您调用该过程时,您会执行类似的操作
DECLARE
l_ignore_indexes types_package.list_of_names_t;
BEGIN
l_ignore_indexes := sample_function;
-- Do something with l_ignore_indexes
END;
或者
DECLARE
l_ignore_indexes types_package.list_of_names_t;
BEGIN
sample_procedure( l_ignore_indexes );
-- Do something with l_ignore_indexes
END;