---create waterfall
Create or replace type Waterfall is Object (name Varchar2 (), height number);
--Create River
Create or replace type Rivertest is Object (name Varchar2 (), length number);
Create or replace procedure Anydatatest
/*
* This example demonstrates a way to pass multiple different data type elements in a collection when parameters are passed
* You can convert all elements of different data types to the Anydata type to add to the collection, and then between programs
* Pass multiple data elements through a collection.
* then the corresponding type of member method is called according to the actual type of the element in the subsequent processing.
*/
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)
)
);
--Traversing the collection
V_index: = V_feature.first;
While (V_index was 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
Examples of usages of anydata data types in Oracle