dbms_xmlgen.getxmltype(context) returns null when the sql table is empty



I have this following function to convert table data to XML. However, whenever the table data is null the resulting XML is null. I want it to add the column names in case of empty table data. What changes should I make in this function.



function XmlToBlob(p_query varchar2) return blob is
ctx dbms_xmlgen.ctxhandle;
xml xmltype;
resultBlob blob;
begin
ctx := dbms_xmlgen.newcontext(p_query);
dbms_xmlgen.setNullHandling(ctx, dbms_xmlgen.empty_tag);
xml := dbms_xmlgen.getxmltype(ctx);
if (xml is not null) then
resultBlob := xml.getBlobVal(NLS_CHARSET_ID('AL32UTF8'));
else
resultBlob := null;
end if;
return resultBlob;
end;

No comments:

Post a Comment