简体   繁体   中英

How to convert blob to clob or how to use extractValue function for BLOB in oracle

I tried using BLOB datatype in extractValue() to fetch text in specified XPATH, but its throwing error for BLOB data type where it is working fine for CLOB data type.

So I tried to convert BLOB to CLOB with below logic as got from stackoverflow

    create function clobfromblob(p_blob blob) return clob is
      l_clob         clob;
      l_dest_offsset integer := 1;
      l_src_offsset  integer := 1;
      l_lang_context integer := dbms_lob.default_lang_ctx;
      l_warning      integer;

   begin

      if p_blob is null then
         return null;
      end if;

      dbms_lob.createTemporary(lob_loc => l_clob
                              ,cache   => false);

      dbms_lob.converttoclob(dest_lob     => l_clob
                            ,src_blob     => p_blob
                            ,amount       => dbms_lob.lobmaxsize
                            ,dest_offset  => l_dest_offsset
                            ,src_offset   => l_src_offsset
                            ,blob_csid    => dbms_lob.default_csid
                            ,lang_context => l_lang_context
                            ,warning      => l_warning);

      return l_clob;

   end;

after using above function I am getting output in unreadable format. Please help in how to convert blob to clob in readable format or how to use extractValue() for BLOB messages

您可以使用包含许多函数来处理 BLOB/CLOB 等的包 OraOpenSource Utils链接

1) Error: PLS-306: wrong number or types of arguments. Xmltype 's constructor for blob data is expecting two parameters. xmltype(blob,csid)

cisd - character set ID of the blob data SELECT NLS_CHARSET_ID('UTF8') csid FROM DUAL;

2) ORA-31011: XML parsing failed. ... LPX-00216: invalid character 31 (0x1F) It's means that oracle is not able to parse xml generated by clobfromblob. invalid character 31 (0x1F) 0x1f is asci hex code for US (Unit Separator). reason of this exception can be wrong encoding during conversion from blob to clob or invalid xml in blob data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM