Parsing large XML file with PL/SQL

后端 未结 1 1675
南旧
南旧 2021-01-15 05:21


I\'m trying to parse quite large XML file. FIle is large enough to make impossible to use VARCHAR2, so I\'ve decided to use CLOB. Code looks fine, but I still get an e

1条回答
  •  -上瘾入骨i
    2021-01-15 05:35

    You are reading the file line by line, but overwritting your xmlClob with each line, not appending. You could build up the CLOB by reading into a varchar2 buffer and appending, but you can also use the DBMS_LOB built-in procedures to do it for you:

    DECLARE
      xmlClob CLOB;
      xmlFile BFILE;
      x XMLType;
    
      src_offset number := 1 ;
      dest_offset number := 1 ;
      lang_ctx number := DBMS_LOB.DEFAULT_LANG_CTX;
      warning integer;
    BEGIN
      xmlFile := BFILENAME('XMLPARSERADRESYCUZK', 'pokus.xml');
      DBMS_LOB.CREATETEMPORARY(xmlClob, true);
      DBMS_LOB.FILEOPEN(xmlFile, DBMS_LOB.FILE_READONLY);
      DBMS_LOB.LOADCLOBFROMFILE(xmlClob, xmlFile, DBMS_LOB.LOBMAXSIZE, src_offset,
        dest_offset, DBMS_LOB.DEFAULT_CSID, lang_ctx, warning);
      x := XMLType.createXML(xmlClob);
      DBMS_LOB.FILECLOSEALL();
      DBMS_LOB.FREETEMPORARY(xmlClob);
      FOR r IN (
    ...
    

    When I use that and load your file I get the output:

    CUZK Pod smdli.t.m 1800/9
    

    You probably want some error checkign around the DBMS_LOB calls, this is just a simple demo.

    0 讨论(0)
提交回复
热议问题