Generating XML content from Relational Table
We are going to load EMP table into a CLOB
CREATE TABLE AMMAR (result CLOB);
Declare
qryctx dbms_xmlgen.ctxhandle; -- declare xml handler
my_result clob;
begin
qryctx:= dbms_xmlgen.newcontext ('select * from emp'); -- associate the
handler with a query
dbms_xmlgen.setrowtag(qryctx, 'EMPS');
-- declare the rowtag for each record
dbms_xmlgen.setmaxrows(qryctx,1);
-- number of rows per fetch ,, may affect performance
loop
my_result:=dbms_xmlgen.getxml(qryctx); --
Retrieve the result into the
exit when
dbms_xmlgen.getnumrowsprocessed(qryctx)=0; -- stop when
there are no more records to fetch
insert into ammar values (my_result);
-- fill the table ammar with the XML result
end loop; end;