首先,他們鍵入需要要在過程之外聲明,以便類型定義對程序外部的代碼可見。您可以在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;
您必須聲明的類型你的程序之外,使一個函數,而不是一個過程,或OUT參數的程序。 – Roger
我假設你在'sample_procedure'中確實沒有'DECLARE',或者至少它不在你放置它的地方。如果你在'AS'之後有一個'DECLARE',你會得到一個語法錯誤。 –