Saturday, September 12, 2009

nested table for hierarchycal xml

CREATE OR REPLACE TYPE test1_type AS OBJECT
(
SOURCE_ID NUMBER(10),
ENTITY_ID_CODE VARCHAR2(3 Byte)
)

CREATE OR REPLACE TYPE test1_type_tbl
AS TABLE OF test1_type;

CREATE OR REPLACE TYPE test2_type AS OBJECT
(
RECEIVER_ID NUMBER(10),
SOURCE_ID NUMBER(10)
)

CREATE OR REPLACE TYPE test2_type_tbl
AS TABLE OF test2_type;

CREATE OR REPLACE TYPE wrapper_type AS OBJECT
(
test_nested_input1 test1_type_tbl,
test_nested_input2 test2_type_tbl
)

CREATE OR REPLACE TYPE wrapper_type_tbl
AS TABLE OF wrapper_type;

create table REALMED_CORP_NESTED_TABLE
(
id INTEGER Primary Key,
Company_Name VarChar2(20),
wrapper_rec wrapper_type_tbl
)
NESTED TABLE wrapper_rec STORE AS nested_wrapper_rec
(NESTED TABLE test_nested_input1 STORE AS nested_Input1_tab
NESTED TABLE test_nested_input2 STORE AS nested_Input2_tab);

insert into REALMED_CORP_NESTED_TABLE
values
(001,
'c12',
wrapper_type_tbl(
wrapper_type(
test1_type_tbl(test1_type(12,'t')),
test2_type_tbl(test2_type(12,12))
))
);

commit

select DBMS_XMLquery.GetXML('select * from REALMED_CORP_NESTED_TABLE') from dual

No comments: