標籤:
---建立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;
oracle中anyData資料類型的使用執行個體