这是使用 ANYDATA 数据类型的可能解决方案:
CREATE OR REPLACE
TYPE my_object AS OBJECT (
some_number NUMBER,
STATIC FUNCTION static_test_function(p_my_objects_tab IN OUT ANYDATA) RETURN NUMBER
);
/
CREATE TYPE my_object_tab_t AS TABLE OF my_object;
/
CREATE OR REPLACE
TYPE BODY my_object AS
STATIC FUNCTION static_test_function(p_my_objects_tab IN OUT ANYDATA) RETURN NUMBER
AS
v_my_objects_tab my_object_tab_t;
v_dummy NUMBER;
v_result NUMBER := 0;
BEGIN
-- get the collection from ANYDATA object - v_dummy holds status (succes or not)
v_dummy := p_my_objects_tab.GetCollection(v_my_objects_tab);
-- as an example, loop through the list and sum up the some_number field
FOR v_i IN v_my_objects_tab.FIRST..v_my_objects_tab.LAST
LOOP
v_result := v_result + v_my_objects_tab(v_i).some_number;
END LOOP;
RETURN v_result;
END;
END;
/
DECLARE
v_my_objects_tab my_object_tab_t;
v_anydata_my_objects_tab ANYDATA;
v_result NUMBER;
BEGIN
-- create the collection and populate it with some sample data
v_my_objects_tab := my_object_tab_t();
v_my_objects_tab.EXTEND();
v_my_objects_tab(v_my_objects_tab.LAST()) := my_object(5);
v_my_objects_tab.EXTEND();
v_my_objects_tab(v_my_objects_tab.LAST()) := my_object(10);
-- create ANYDATA object from the collection
v_anydata_my_objects_tab := ANYDATA.ConvertCollection(v_my_objects_tab);
-- call the static function expecting ANYDATA parameter
v_result := my_object.static_test_function(v_anydata_my_objects_tab);
dbms_output.put_line(v_result);
END;
/
输出:15