---创建waterfall
create or replace type waterfall is object(name varchar2(30),height number);
--创建river
create or replace type rivertest is object(name varchar2(30),length number);
create or replace procedure anydataTest
/*
*该实例演示了一种在参数传递时可以在集合中传递多个不同数据类型元素的例子
*可以将不同数据类型的元素全部转换成anyData类型添加到集合中,然后在程序间
*通过集合来传递多个数据元素。
*然后在后续的处理中根据元素的实际类型分别调用对应类型的成员方法做相应的处理
*/
is
type feature_array is varray(2) of sys.anydata;
v_feature feature_array;
wf waterfall;
rv rivertest;
ret_val number;
v_index pls_integer;
begin
v_feature := feature_array(
anydata.convertobject(
waterfall('waterfall1',12)
),
anydata.convertobject(
rivertest('rivertes',34)
)
);
--遍历集合
v_index := v_feature.first;
while(v_index is not null)
loop
case v_feature(v_index).gettypename
when 'BISBNK.WATERFALL' then
ret_val := v_feature(v_index).getobject(wf);
dbms_output.put_line('waterfall name:'||wf.name ||' height:'||wf.height);
when 'BISBNK.RIVERTEST' then
ret_val := v_feature(v_index).getobject(rv);
dbms_output.put_line('river name:'||rv.name ||' length:'||rv.length);
else
dbms_output.put_line('unknow type:'||v_feature(v_index).gettypename);
end case;
v_index := v_feature.next(v_index);
end loop;
exception
when no_data_found then
dbms_output.put_line('no data found');
raise;
when others then
dbms_output.put_line(sqlcode||': '||sqlerrm);
raise;
end;