oracle中anyData資料類型的使用執行個體

來源:互聯網
上載者:User

標籤:

---建立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資料類型的使用執行個體

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.