create table toys (
toy_id integer,
toy_name varchar2(30),
price number,
colour varchar2(30)
)
Table created.
begin
insert into toys values (1, 'Cheapasaurus Rex', 0.99, 'blue');
insert into toys values (2, 'Costsalottasaurs', 99.99, 'green');
insert into toys values (3, 'Bluesaurus', 21.99, 'blue');
commit;
end;
1 row(s) inserted.
select * from toys
TOY_ID | TOY_NAME | PRICE | COLOUR | 1 | Cheapasaurus Rex | .99 | blue | 2 | Costsalottasaurs | 99.99 | green | 3 | Bluesaurus | 21.99 | blue |
---|
select xmlforest(toy_id, toy_name, price, colour).getClobVal() xdoc from toys
XDOC | <TOY_ID>1</TOY_ID><TOY_NAME>Cheapasaurus Rex</TOY_NAME><PRICE>.99</PRICE><COLOUR>blue</COLOUR> | <TOY_ID>2</TOY_ID><TOY_NAME>Costsalottasaurs</TOY_NAME><PRICE>99.99</PRICE><COLOUR>green</COLOUR> | <TOY_ID>3</TOY_ID><TOY_NAME>Bluesaurus</TOY_NAME><PRICE>21.99</PRICE><COLOUR>blue</COLOUR> |
---|
select xmlagg(xmlelement("ROW", xmlforest(toy_id, toy_name, price, colour))).getClobVal() xdoc
from toys
XDOC | <ROW><TOY_ID>1</TOY_ID><TOY_NAME>Cheapasaurus Rex</TOY_NAME><PRICE>.99</PRICE><COLOUR>blue</COLOUR></ROW><ROW><TOY_ID>2</TOY_ID><TOY_NAME>Costsalottasaurs</TOY_NAME><PRICE>99.99</PRICE><COLOUR>green</COLOUR></ROW><ROW><TOY_ID>3</TOY_ID><TOY_NAME>Bluesaurus</TOY_NAME><PRICE>21.99</PRICE><COLOUR>blue</COLOUR></ROW> |
---|
select xmltype(cursor(select * from toys)).getClobVal() xdoc from dual
XDOC | <?xml version="1.0"?> <ROWSET> <ROW> <TOY_ID>1</TOY_ID> <TOY_NAME>Cheapasaurus Rex</TOY_NAME> <PRICE>.99</PRICE> <COLOUR>blue</COLOUR> </ROW> <ROW> <TOY_ID>2</TOY_ID> <TOY_NAME>Costsalottasaurs</TOY_NAME> <PRICE>99.99</PRICE> <COLOUR>green</COLOUR> </ROW> <ROW> <TOY_ID>3</TOY_ID> <TOY_NAME>Bluesaurus</TOY_NAME> <PRICE>21.99</PRICE> <COLOUR>blue</COLOUR> </ROW> </ROWSET> |
---|
select dbms_xmlgen.getxml('select * from toys') xdoc from dual
XDOC | <?xml version="1.0"?> <ROWSET> <ROW> <TOY_ID>1</TOY_ID> <TOY_NAME>Cheapasaurus Rex</TOY_NAME> <PRICE>.99</PRICE> <COLOUR>blue</COLOUR> </ROW> <ROW> <TOY_ID>2</TOY_ID> <TOY_NAME>Costsalottasaurs</TOY_NAME> <PRICE>99.99</PRICE> <COLOUR>green</COLOUR> </ROW> <ROW> <TOY_ID>3</TOY_ID> <TOY_NAME>Bluesaurus</TOY_NAME> <PRICE>21.99</PRICE> <COLOUR>blue</COLOUR> </ROW> </ROWSET> |
---|