Question

I need to generate a XML and write it to a file. I have used utl_file.put_line. It creates the file, but nothing is written into it. Also, it shows no errors. I've already checked if I have the permissions to write on the directory. Code:

SET serveroutput ON;
DECLARE
    ctx DBMS_XMLGEN.CTXHANDLE;
    resposta CLOB;
    xml_file utl_file.file_type;
BEGIN
    xml_file:=utl_file.fopen ('DATA_PUMP_DIR', 'xml.txt', 'W');
    ctx := dbms_xmlgen.newContext ('select * from tb_museu M where M.cnpj=111111 OR   M.cnpj=222222');
    dbms_xmlgen.setRowsetTag (ctx, 'TODOS_OS_MUSEUS');
    dbms_xmlgen.setRowTag (ctx, 'MUSEU');
    resposta :=dbms_xmlgen.getXML (ctx);
    utl_file.put_line (xml_file,'teste');
    --utl_file.put_line (xml_file,resposta);
   dbms_xmlgen.closeContext(ctx);
END;
/
Was it helpful?

Solution

For performance reasons UTL_FILE uses a buffer which is periodically flushed to the actual file on disk. Generally you don't need to worry about flushing, except you do need to close the file at the end with UTL_FILE.fclose(xmlfile);.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top