Convert a blob to base64

hi, someone who can help me how to convert a blob oracle in base64.encode,
and viceverse.
please some idea
tanks
alex

i saw a bit code about this convertions,
//one side
ResultSet r = ...........
BLOB b = (BLOB)r.getBlob('ICON');//BLOB is oracle type not Blob
byte[] base = b.getBytes();
Strgin res = Base64.encode(base);
//other side
String dec = datos;// data in base64
byte[] base = Base64.decode(dec.getBytes());
BLOB b = null;
b.setBytes(base);
is this code correct????
i tried to test but a have an error with
public static void BLOBToFile(BLOB datos,String path)
try
FileOutputStream fos=new FileOutputStream(path);
byte[] tempBin=new byte[8];
long cant=1;
while (cant <= datos.length())
tempBin=datos.getBytes(cant,Integer.MAX_VALUE);
cant = Integer.MAX_VALUE+1;
fos.write(tempBin);
fos.close();
catch(Exception e)
e.printStackTrace();
and the error is outOfMemory
how can i test my code??
alex

Similar Messages

  • Function convertion from blob to clob

    Plesae need help,to make function convert from blob to clob
    i have function but not work when coulmn of blob is vey large
    =========================================================================================
    CREATE OR REPLACE PACKAGE BODY "SHB_PACKAGE"
    AS
    FUNCTION blob2clob (l_blob BLOB)
    RETURN CLOB
    IS
    l_clob CLOB;
    l_src_offset NUMBER;
    l_dest_offset NUMBER;
    l_blob_csid NUMBER := DBMS_LOB.default_csid;
    v_lang_context NUMBER := DBMS_LOB.default_lang_ctx;
    l_warning NUMBER;
    l_amount NUMBER := dbms_lob.lobmaxsize;
    BEGIN
    IF l_blob is null
    THEN
    return null;
    ELSE
    DBMS_LOB.createtemporary (l_clob, TRUE);
    l_src_offset := 1;
    l_dest_offset := 1;
    l_amount := NVL(DBMS_LOB.getlength (l_blob),0);
    DBMS_LOB.converttoclob (l_clob,
    l_blob,
    l_amount,
    l_src_offset,
    l_dest_offset,
    0,
    v_lang_context,
    l_warning
    RETURN l_clob;
    END IF;
    END;
    END SHB_package;

    thanks,function is working fine
    issue duo to i used under informatice and bug in informatica
    Edited by: user8929623 on Jan 17, 2010 1:39 AM

  • How to convert oracle BLOB to String

    Hi,
    I am working on an GIS project using Oracle database which stores the spatial data. When I read the polygon points data which is saved as BLOB type in database table and convert the BLOB to byte[], there is no problem. However when the data is converted to Character, those characters are not recognized something like this:
    �����������?�����?���w�����������������!����?o����s��8��n�����H��?
    ������������������ �?&�?�����|��?��������?���������������L�?
    This is the method I used to convert BLOB to String below:
    -----mapb is the BLOB instance.
    byte[] images = mapb.getBytes(1,(int)mapb.length());
    String newstring = new String(images);
    Is that decoding problem?
    Can somebody help me for this problem?
    Thanks in advance!
    XR

    Hi,
    Thanks for reply,
    Actually the data is ESRI spatial data saved in ORACLE database.
    the BLOB is not a column, it is part of column of st_geometry.
    I looked at some docs in ESRI, they save points which is the last part of st_geometry field with BLOB type. I use the jdbc to get the geometry data and use STRUCT and Datum class to get all members of the st_geometry data. There are 14 members in the field, I can cast most of them into String through Datum instance, but the object #14 is BLOB, will not allow me cast it to String directly, so I use byte[] and cast it though new String().
    some of the lines here:
    STRUCT st = (oracle.sql.STRUCT) rs.getObject("shape");
    Datum[] dtms = st.getOracleAttributes();
    BLOB mapb = null;
    for (int i=0;i<dtms.length;i++){
    if (!(dtms[i] == null)){
    if (i==13){
    mapb = (BLOB)dtms;
    } else {
    log.info("data" + i + "=" + dtms[i].stringValue());
    byte[] images = mapb.getBytes(1,(int)mapb.length());
    String newstring = new String(images);
    Thanks again for your reply.
    XR

  • How to File Convert to Blob? help me

    Hey Guys...........
    How to convert inputStream to blob ????
    kit = new RTFEditorKit();
    Document doc = kit.createDefaultDocument();
    InputStream is = getUploadedFile().getInputStream();
    DCIteratorBinding iterTemplate = ADFUtils.findIterator("TemplateVOIterator");
    Row currentRow = iterTemplate.getCurrentRow();
    String templateId = currentRow.getAttribute("Id").toString();
    currentRow.setAttribute("TemplateFile", ????); in here Blob file....
    "is" convert to blob ???
    Regards Ninja,
    Edited by: Ninja on Jul 21, 2011 7:04 PM
    Edited by: Ninja on Jul 21, 2011 11:39 PM

    Timo Hahn wrote:
    Well, it's all in the sample Frank pointed you to:
    //your code
    kit = new RTFEditorKit();
    Document doc = kit.createDefaultDocument();
    InputStream is = getUploadedFile().getInputStream();
    DCIteratorBinding iterTemplate = ADFUtils.findIterator("TemplateVOIterator");
    Row currentRow = iterTemplate.getCurrentRow();
    String templateId = currentRow.getAttribute("Id").toString();
    currentRow.setAttribute("TemplateFile", newBlobDomainForInputStream(is)); in here Blob file....
    private BlobDomain newBlobDomainForInputStream(InputStream in) throws SQLException, IOException {
    BlobDomain b = new BlobDomain();
    OutputStream out = b.getBinaryOutputStream();
    writeInputStreamToOutputStream(in,out);
    in.close();
    out.close();
    return b;
    private static void writeInputStreamToOutputStream(InputStream in, OutputStream out) throws IOException {
    byte[] buffer = new byte[8192];
    int bytesRead = 0;
    while ((bytesRead = in.read(buffer, 0, 8192)) != -1) {
    out.write(buffer, 0, bytesRead);
    }TimoI can new method..... This is GOOD..
    *> kit = new RTFEditorKit();*
    *> Document doc = kit.createDefaultDocument();*
    *> InputStream is = getUploadedFile().getInputStream();*
    byte[] bytes = IOUtils.toByteArray(is);
    Blob blob = new SerialBlob(bytes);
    currentRow.setAttribute("TemplateFile", blob);
    like
    Edited by: Ninja on Jul 28, 2011 10:59 PM

  • Convert message content to base64 code format.

    Hi,
    While sending the file to the target directory ,need to convert the content to base64 code format.How we  can achieve this.
    Regards,
    Hymavathi

    this is a duplicate thread :convert message content to base64 code format.
    Please close this one.

  • Converting to BLOB in AL32UTF8 destroys German Umlaut characters

    Test Case.
    Two database
    (A) NLS_CHARACTERSET= WE8MSWIN1252
    (B) AL32UTF8
    I have used the following function to convert CLOB data to BLOB
    create or replace function clob_to_blob (p_clob_in in clob)
    return blob
    is
    v_blob blob;
    v_offset integer;
    v_buffer_varchar varchar2(32000);
    v_buffer_raw raw(32000);
    v_buffer_size binary_integer := 32000;
    begin
      if p_clob_in is null then
        return null;
      end if;
      DBMS_LOB.CREATETEMPORARY(v_blob, TRUE);
      v_offset := 1;
      FOR i IN 1..CEIL(DBMS_LOB.GETLENGTH(p_clob_in) / v_buffer_size)
      loop
        dbms_lob.read(p_clob_in, v_buffer_size, v_offset, v_buffer_varchar);
        v_buffer_raw := utl_raw.cast_to_raw(v_buffer_varchar);
        dbms_lob.writeappend(v_blob, utl_raw.length(v_buffer_raw), v_buffer_raw);
        v_offset := v_offset + v_buffer_size;
      end loop;
      return v_blob;
    end clob_to_blob;If i input ÄÖÜ to the function,In WE8MSWIN1252 the returning BLOB looks ok, but in AL32UTF8 the BLOB's characters comes out like ÄÖÜ.
    Now if i were to save the values (CLOB and BLOB) in both occations the CLOB will be stored without problem, but BLOB will be saved incorrectly only in AL32UTF8 environment.
    The only difference between the two db's are the characterset.
    Is this a know limitation or am i doing something wrong.
    PS. I have seen similar behaviour when using dbms_lob.converttoblob
    thank you

    When describing the problem you missed one very important point: how do you look at the content of the BLOB to tell if it is OK or not? Remember that observation usually influences the experiment results ;-)
    The sequence like ÄÖÜ looks like AL32UTF8 encoding of umlauts viewed with a WE8MSWIN1252 viewer. If you look with a viewer that expects WE8MSWIN1252 at a BLOB that contains AL32UTF8 text (which is the case with an AL32UTF8 database), then this is what you should expect.
    -- Sergiusz

  • Blob to base64 encoded XML

    Hi,
    We have a table with two columns (Name varchar2, Picture Blob).
    How do we get XML output containing rows from table, with Picture (blob column) being base64 encoded.
    Note: I have tried using utl_encode.base64_encode, but getting error due to large size of Picture.
    Thanks,
    Yj

    I am not sure what you finally want to accomplish (create a binary xml?), but to base64 encode a blob you could do it »stepwise«:
    declare
       bl            blob;   /* your picture blob */
       bl_enc        blob;  /*  encoded blob */
       offset        integer            := 1;
       amt           integer            := 20000;
    begin
       dbms_lob.createtemporary (bl_enc, false);
       while dbms_lob.substr (bl, amt, offset) is not null
       loop
          dbms_lob.append (bl_enc, utl_encode.base64_encode (dbms_lob.substr (bl, amt, offset)));
          offset := offset + amt;
       end loop;
       convert_to_xml(bl_enc);
       dbms_lob.freetemporary (bl_enc);
    end;
    /

  • Converting from Blob to pdf problem

    Dear all
    I have a small problem i hope someone can help me with. I wrote a code that saves a pdf in a database as blob, but when trying to retrieve this blob back and show it as a pdf i had a problem.
    When i tried to show the pdf it appeared as a long stream like the following
    %PDF-1.6 %âãÏÓ 27 0 obj <> endobj xref 27 21 0000000016 0000 ...............etc.
    so it has the same structure of my original pdf except that it's a long stream in only one line . The original pdf looks like the following
    %PDF-1.6
    %âãÏÓ
    27 0 obj
    <</Linearized 1/L 82015/O 38/E 6717/N 1/T 81428/H [ 716 197]>>
    endobj
    xref
    27 21
    ............etc.
    So if anyone can help to change that stream into a pdf again, i will really appreciate it. I attached the 2 files (the stream and the pdf).
    Thanks in advance

    You should save the PDF data to a file and loading that into your HTML content.
    This forum post may help:
    http://forums.adobe.com/thread/430491

  • Converting a blob to clob

    Hi,
    Has anybody been successful in using the DBMS_LOB.ConvertToClob procedure. It's giving me "invalid lob locator specified" error.
    here's my code
    create or replace function convert_blob_to_clob(p_file in varchar2) return clob is
    v_file_blob blob;
    v_file_clob clob;
    v_file_size integer := dbms_lob.lobmaxsize;
    v_dest_offset integer := 1;
    v_src_offset integer := 1;
    v_blob_csid number := dbms_lob.default_csid;
    v_lang_context number := dbms_lob.default_lang_ctx;
    v_warning integer;
    begin
    select a.blob_content into v_file_blob
    from txt_files a
    where name = p_file;
    dbms_lob.convertToClob(v_file_clob, v_file_blob,v_file_size,
    v_dest_offset, v_src_offset, v_blob_csid,
    v_lang_context, v_warning);
    if v_warning = 0 then
    return v_file_clob;
    end if;
    end;
    Any help would be greatly appreciated
    Thanks.

    I figured it out...
    here 's the new code..
    create or replace function convert_blob_to_clob(p_file in varchar2) return clob is
    v_file_blob blob;
    v_file_clob clob;
    v_file_size integer := dbms_lob.lobmaxsize;
    v_dest_offset integer := 1;
    v_src_offset integer := 1;
    v_blob_csid number := dbms_lob.default_csid;
    v_lang_context number := dbms_lob.default_lang_ctx;
    v_warning integer;
    begin
    select a.blob_content into v_file_blob
    from txt_files a
    where name = p_file;
    -- the following line solved it
    DBMS_LOB.CREATETEMPORARY(v_file_clob, TRUE);
    dbms_lob.convertToClob(v_file_clob, v_file_blob,v_file_size,
    v_dest_offset, v_src_offset, v_blob_csid,
    v_lang_context, v_warning);
    if v_warning = 0 then
    return v_file_clob;
    end if;
    end;

  • Convert .xls BLOB to .pdf

    Hello,
    One of my customers has a lot fo .xls files stored as BLOB in a table. They would like to download those as PDF. Is there a method or a tool to do this on demand?
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    -------------------------------------------------------------------

    Hello Tony,
    This is exactly what I would like to avoid:
    1. cron or batch jobs
    2. accessing the file system
    3. using some additional tools you need to install on the server
    4. taking care of the OS
    What I had in mind is some code I could install in the database (java?) or configuring the webserver to do that for me. Maybe this is just not possible.
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    -------------------------------------------------------------------

  • A blob column in xml

    Hi,
    I have a blob column in some table. It is for example an jpg image. The size is more than 32k (for example size:152287 with dbms_lob.getlength)
    How can I get this column in a xml document because I want to use the xml file for importing in a different Oracle schema.
    Thanks in advance,
    Henk

    Extracting the BLOB is not the hardest part, SQL/XML function such as XMLElement() can read the content natively and convert it to a text node in xs:hexBinary format :
    SQL> select xmlelement("Image", image)
      2  from test_jdbc_blob
      3  where img_id = 'Koala.jpg' ;
    XMLELEMENT("IMAGE",IMAGE)
    <Image>FFD8FFE000104A46494600010201006000600000FFEE000E41646F626500640000000001F
    Other option is to convert the BLOB to base64 and feed it to an element similarly, though it requires a little more code.
    DBMS_XMLDOM has some methods to manipulate large binary streams too.

  • How to read a BLOB (base64 - stream) from XML-file in ORACLE10

    ORACLE 10g
    PL/SQL function
    MY XML-file:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <slo xmlns="http://www.example.org/detection">
         <LekKey>1999_036371_509627</LekKey>
         <HuiNum>46</HuiNum>
         <Res></Res>
         <InfLig>TEST STRUI AFGESTORVEN - PLAANSTRAAT 46</InfLig>
         <XWGS>3.637028</XWGS>
         <YWGS>50.962667</YWGS>
         <Pei>EANDIS</Pei>
         <DatPei>1999-11-30T10:17:36.000+01:00</DatPei>
         <Kan> </Kan>
         <Doc>UEsDBBQABgAIAAAAIQB5gHbnswEAAHcGAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAACAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC0VUtP20AQviP1P1h7rewNPVRVFYcDj2OL1FTluqzH
    ycK+tDMB8u8764AVwMSBiIsle/d7zLc74+nJg7PFHSQ0wdfiuJqIArwOjfGLWvydX5Q/RIGkfKNs8FCL
    NaA4mX05ms7XEbBgtMdaLIniTylRL8EprEIEzyttSE4Rv6aFjErfqgXIb5PJd6mDJ/BUUuYQs+kZtGpl
    qTh/4M8bJ9EvRHG62ZelamFcxufvchCRwOILiIrRGq2Ia5N3vnnhq3z0VDGy24NLE/ErG39DIa8897Qt
    8DbuJg7XchOhK+Y3559MA8WlSvRLOS5W3ofUyCboleOgqt3KA6WFtjUaenxmiyloQOSDdbbqV5wy/qnk
    IR96hRTclbPSELjLFCIeH2ynJ818kMhAH/uQhy4LpLUFPFj6VRIb3l0RbMn/M7Q8b1vQfKvHz8RhmbHV
    RmILO64GRHxQ+4g877Vy7ODxkXnUwj1c//k0F1vko0ZaHgJzdW1hj8TfGUZPPWqCeLCB7J6HX/+OZpck
    bWxQSwECLQAUAAYACAAAACEAdD85esIAAAAoAQAAHgAAAAAAAAAAAAAAAADqNAkAY3VzdG9tWG1sL19y
    ZWxzL2l0ZW0xLnhtbC5yZWxzUEsBAi0AFAAGAAgAAAAhANouSfniAAAAVQEAABgAAAAAAAAAAAAAAAAA
    8DYJAGN1c3RvbVhtbC9pdGVtUHJvcHMxLnhtbFBLAQItABQABgAIAAAAIQD+hDirOAIAAMwHAAASAAAA
    AAAAAAAAAAAAADA4CQB3b3JkL2ZvbnRUYWJsZS54bWxQSwECLQAUAAYACAAAACEAp/3kQ44BAADeAgAA
    EQAAAAAAAAAAAAAAAACYOgkAZG9jUHJvcHMvY29yZS54bWxQSwECLQAUAAYACAAAACEAqchcqowAAADa
    AAAAEwAAAAAAAAAAAAAAAABdPQkAY3VzdG9tWG1sL2l0ZW0xLnhtbFBLAQItABQABgAIAAAAIQBgX/2I
    CwEAALoBAAAUAAAAAAAAAAAAAAAAAEI+CQB3b3JkL3dlYlNldHRpbmdzLnhtbFBLAQItABQABgAIAAAA
    IQDQwaCR/gEAAGgEAAAQAAAAAAAAAAAAAAAAAH8/CQBkb2NQcm9wcy9hcHAueG1sUEsFBgAAAAASABIA
    pQQAALNCCQAAAA==</Doc>
    </slo>
    I have to write an PL/SQL function where I can read all the data in the XML-file (see attach).
    In this XML there is a BLOB stored (base64 - stream -> that contains always a MSWORD document).
    1) how can I extract this BLOB + the other data in the XML and save this data in a ORACLE table?
    2) how can I decode this BLOB and save this MSWORD-document to a fileserver?

    First extract your data as CLOB (as it's character based)...
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select xmltype('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
      2  <slo xmlns="http://www.example.org/detection">
      3    <LekKey>1999_036371_509627</LekKey>
      4    <HuiNum>46</HuiNum>
      5    <Res></Res>
      6    <InfLig>TEST STRUI AFGESTORVEN - PLAANSTRAAT 46</InfLig>
      7    <XWGS>3.637028</XWGS>
      8    <YWGS>50.962667</YWGS>
      9    <Pei>EANDIS</Pei>
    10    <DatPei>1999-11-30T10:17:36.000+01:00</DatPei>
    11    <Kan> </Kan>
    12    <Doc>UEsDBBQABgAIAAAAIQB5gHbnswEAAHcGAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAC0VUtP20AQviP1P1h7rewNPVRVFYcDj2OL1FTluqzHycK+tDMB8u8764AVwMSBiIsle/d7zLc74+nJg7PFHSQ0wdfiuJqIArwOjfGLWvydX5Q/RIGkfKNs8FCLNaA4mX05ms7XEbBgtMdaLIniTylRL8EprEIEzyttSE4Rv6aFjErfqgXIb5PJd6mDJ/BUUuYQs+kZtGplqTh/4M8bJ9EvRHG62ZelamFcxufvchCRwOILiIrRGq2Ia5N3vnnh
    q3z0VDGy24NLE/ErG39DIa8897Qt8DbuJg7XchOhK+Y3559MA8WlSvRLOS5W3ofUyCboleOgqt3KA6WFtjUaenxmiyloQOSDdbbqV5wy/qnkIR96hRTclbPSELjLFCIeH2ynJ818kMhAH/uQhy4LpLUFPFj6VRIb3l0RbMn/M7Q8b1vQfKvHz8RhmbHVRmILO64GRHxQ+4g877Vy7ODxkXnUwj1c//k0F1vko0ZaHgJzdW1hj8TfGUZPPWqCeLCB
    7J6HX/+OZpckbWxQSwECLQAUAAYACAAAACEAdD85esIAAAAoAQAAHgAAAAAAAAAAAAAAAADqNAkAY3VzdG9tWG1sL19yZWxzL2l0ZW0xLnhtbC5yZWxzUEsBAi0AFAAGAAgAAAAhANouSfniAAAAVQEAABgAAAAAAAAAAAAAAAAA8DYJAGN1c3RvbVhtbC9pdGVtUHJvcHMxLnhtbFBLAQItABQABgAIAAAAIQD+hDirOAIAAMwHAAASAAAAAAAA
    AAAAAAAAADA4CQB3b3JkL2ZvbnRUYWJsZS54bWxQSwECLQAUAAYACAAAACEAp/3kQ44BAADeAgAAEQAAAAAAAAAAAAAAAACYOgkAZG9jUHJvcHMvY29yZS54bWxQSwECLQAUAAYACAAAACEAqchcqowAAADaAAAAEwAAAAAAAAAAAAAAAABdPQkAY3VzdG9tWG1sL2l0ZW0xLnhtbFBLAQItABQABgAIAAAAIQBgX/2ICwEAALoBAAAUAAAAAAAA
    AAAAAAAAAEI+CQB3b3JkL3dlYlNldHRpbmdzLnhtbFBLAQItABQABgAIAAAAIQDQwaCR/gEAAGgEAAAQAAAAAAAAAAAAAAAAAH8/CQBkb2NQcm9wcy9hcHAueG1sUEsFBgAAAAASABIApQQAALNCCQAAAA==</Doc>
    13  </slo>') as xml from dual)
    14  --
    15  -- end of test data
    16  --
    17  select x.*
    18  from   t
    19        ,xmltable(xmlnamespaces(default 'http://www.example.org/detection'),
    20                  '/slo'
    21                  passing t.xml
    22                  columns lekkey varchar(30) path './LekKey'
    23                         ,doc    clob        path './Doc'
    24*                ) x
    SQL> /
    LEKKEY                         DOC
    1999_036371_509627             UEsDBBQABgAIAAAAIQB5gHbnswEAAHcGAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAACAAAA
                                   AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                   AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                   AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                   AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                   AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                   AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                   AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                   AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                                   AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC0VUtP20AQviP1P1h7rewNPVRVFYcDj2OL1FTluqzH
                                   ycK+tDMB8u8764AVwMSBiIsle/d7zLc74+nJg7PFHSQ0wdfiuJqIArwOjfGLWvydX5Q/RIGkfKNs8FCL
                                   NaA4mX05ms7XEbBgtMdaLIniTylRL8EprEIEzyttSE4Rv6aFjErfqgXIb5PJd6mDJ/BUUuYQs+kZtGpl
                                   qTh/4M8bJ9EvRHG62ZelamFcxufvchCRwOILiIrRGq2Ia5N3vnnhq3z0VDGy24NLE/ErG39DIa8897Qt
                                   8DbuJg7XchOhK+Y3559MA8WlSvRLOS5W3ofUyCboleOgqt3KA6WFtjUaenxmiyloQOSDdbbqV5wy/qnk
                                   IR96hRTclbPSELjLFCIeH2ynJ818kMhAH/uQhy4LpLUFPFj6VRIb3l0RbMn/M7Q8b1vQfKvHz8RhmbHV
                                   RmILO64GRHxQ+4g877Vy7ODxkXnUwj1c//k0F1vko0ZaHgJzdW1hj8TfGUZPPWqCeLCB7J6HX/+OZpck
                                   bWxQSwECLQAUAAYACAAAACEAdD85esIAAAAoAQAAHgAAAAAAAAAAAAAAAADqNAkAY3VzdG9tWG1sL19y
                                   ZWxzL2l0ZW0xLnhtbC5yZWxzUEsBAi0AFAAGAAgAAAAhANouSfniAAAAVQEAABgAAAAAAAAAAAAAAAAA
                                   8DYJAGN1c3RvbVhtbC9pdGVtUHJvcHMxLnhtbFBLAQItABQABgAIAAAAIQD+hDirOAIAAMwHAAASAAAA
                                   AAAAAAAAAAAAADA4CQB3b3JkL2ZvbnRUYWJsZS54bWxQSwECLQAUAAYACAAAACEAp/3kQ44BAADeAgAA
                                   EQAAAAAAAAAAAAAAAACYOgkAZG9jUHJvcHMvY29yZS54bWxQSwECLQAUAAYACAAAACEAqchcqowAAADa
                                   AAAAEwAAAAAAAAAAAAAAAABdPQkAY3VzdG9tWG1sL2l0ZW0xLnhtbFBLAQItABQABgAIAAAAIQBgX/2I
                                   CwEAALoBAAAUAAAAAAAAAAAAAAAAAEI+CQB3b3JkL3dlYlNldHRpbmdzLnhtbFBLAQItABQABgAIAAAA
                                   IQDQwaCR/gEAAGgEAAAQAAAAAAAAAAAAAAAAAH8/CQBkb2NQcm9wcy9hcHAueG1sUEsFBgAAAAASABIA
                                   pQQAALNCCQAAAA==
    SQL>Then, you can convert the CLOB to a BLOB by doing your base64 decoding.

  • Unable to convert BLOB to XML using XMLTYPE

    Hello (XML) Experts
    I need your help with manipulating a BLOB column containing XML data - I am encountering the following error:
    ORA-31011: XML parsing failed
    ORA-19202: Error occurred in XML processing
    LPX-00200: could not convert from encoding UTF-8 to WINDOWS-1252
    Error at line 1
    ORA-06512: at "SYS.XMLTYPE", line 283
    I am on Windows 7 64 bit, Oracle 11.2.0.3 64 bit and database character set is WE8MSWIN1252, NLS_LANG is set to AMERICAN_AMERICA.AL32UTF8. The BLOB column contains the following XML data:
    <?xml version="1.0" encoding="utf-8"?>
    <Root CRC="-4065505">
      <Header Converted="0">
        <Version Type="String" Value="512" />
        <Revision Type="String" Value="29" />
        <SunSystemsVersion Type="String" Value="" />
        <Date Type="String" Value="20080724" />
        <Time Type="String" Value="165953" />
        <DAG Type="String" Value="" />
        <ChkID Type="String" Value="" />
        <FormType Type="String" Value="1" />
        <DB Type="String" Value="AllBusinessUnits" />
        <FuncID Type="String" Value="SOE" />
        <Status Type="String" Value="" />
        <FileType Type="String" Value="SFL" />
        <Descriptions>
          <Default Type="String" Value="Sales Order Entry" />
          <L01 Type="String" Value="Sales Order Entry" />
          <L33 Type="String" Value="Saisie commande client" />
          <L34 Type="String" Value="Entrada de órdenes de venta" />
          <L39 Type="String" Value="Inserimento ordine di vendita" />
          <L49 Type="String" Value="Aufträge erfassen" />
          <L55 Type="String" Value="Entrada de pedido de venda" />
          <L81 Type="String" Value="å?—注オーダー入力" />
          <L86 Type="String" Value="销售订å?•å½•å…¥" />
          <L87 Type="String" Value="銷售訂單錄入" />
        </Descriptions>
      </Header>
    <FormDesignerAppVer Type="String" Value="5.1" SFLOnly="1" />
    </Root>I am using the XMLTYPE constructor and passing in the BLOB column and the character set id of the XML data stored in the BLOB column in order to extract and update a node in the XML as follows:
    select xmltype(srce_form_detail,873) from SRCE_FORM where 873 above corresponds to the utf-8 encoding of the XML data in the BLOB column i.e. AL32UTF8, but this results in the above error.
    I have also tried converting the BLOB to a CLOB first as below where BLOB2CLOB is a function that converts the BLOB to a CLOB:
    select xmltype(BLOB2CLOB(srce_form_detail)).EXTRACT('/Root/Header/DB').getStringVal() XMLSrc  from SRCE_FORM;This results in the following error:
    ORA-31011: XML parsing failed
    ORA-19202: Error occurred in XML processing
    LPX-00210: expected '<' instead of '¿'
    Error at line 1
    ORA-06512: at "SYS.XMLTYPE", line 272
    ORA-06512: at line 1
    Looking at the XML in the BLOB I noticed that it contains a BOM(byte order mark) and this is causing the XML parsing to fail and I don't know how to deal with it and I don't want to simply SUBSTR it out.
    What I am trying to achieve is to extract the contents of the DB node in the XML and depending on its value I need to update the 'Value' part of that node. I am stuck at the point of extracting the contents of the DB node.
    I hope I have provided enough information and I would appreciate any suggestions on how best to resolve this - my XML knowledge is very limited so I would appreciate any help.
    Regards,
    Mohinder

    Hi Marc
    Thanks for your response.
    You are correct that the blob contains Japanese and Chinese characters but I was expecting that using the XMLTYPE constructor would convert the character set albeit with some data loss or then not display the Chinese and Japanese characters correctly.
    It seems to me that XMLTYPE is not handling/interpreting the BOM contained in the BLOB since even converting the BLOB to CLOB is resulting in an error. If I use SUBSTR and ignore the BOM to extract the XML from the BLOB then it works and as expected the Chinese and Japanese characters are not displayed correctly, they are displayed as '¿' corresponding to the lines beginning with L81, L86 & L87 , see below:
    select xmltype(SUBSTR(BLOB2CLOB(srce_form_detail),4)) from SRCE_FORM
    <?xml version="1.0" encoding="utf-8"?>
    <Root CRC="-4065505">
      <Header Converted="0">
        <Version Type="String" Value="512" />
        <Revision Type="String" Value="29" />
        <SunSystemsVersion Type="String" Value="" />
        <Date Type="String" Value="20080724" />
        <Time Type="String" Value="165953" />
        <DAG Type="String" Value="" />
        <ChkID Type="String" Value="" />
        <FormType Type="String" Value="1" />
        <DB Type="String" Value="AllBusinessUnits" />
        <FuncID Type="String" Value="SOE" />
        <Status Type="String" Value="" />
        <FileType Type="String" Value="SFL" />
        <Descriptions>
          <Default Type="String" Value="Sales Order Entry" />
          <L01 Type="String" Value="Sales Order Entry" />
          <L33 Type="String" Value="Saisie commande client" />
          <L34 Type="String" Value="Entrada de ¿¿rdenes de venta" />
          <L39 Type="String" Value="Inserimento ordine di vendita" />
          <L49 Type="String" Value="Auftr¿¿ge erfassen" />
          <L55 Type="String" Value="Entrada de pedido de venda" />
          <L81 Type="String" Value="¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿" />
          <L86 Type="String" Value="¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿" />
          <L87 Type="String" Value="¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿" />
        </Descriptions>
      </Header>Can you please let me know how I can extract the binary dump of the BLOB and post it on the forum as I don't know how to do this. Below is snippet of the hexadecimal dump, that includes the BOM. I can post the full hexadecimal dump if this can help you to reproduce the error ?
    EFBBBF3C3F786D6C2076657273696F6E3D22312E302220656E636F64696E673D227574662D38223F3E0D0A3C526F6F74204352433D222D34303635353035223E0D0A20203C48656164657220436F6E7665727465643D2230223E0D0A202020203C56657273696F6E20547970653D22537472696E67222056616C75653D2235313222202F3E0D0A202020203C5265766973696F6E20547970653D22537472696E67222056616C75653D22323922202F3E0D0A202020203C53756E53797374656D7356657273696F6E20547970653D22537472696E67222056616C75653D2222202F3E0D0A202020203C4461746520547970653D22537472696E67222056616C75653D22323030383037323422202F3E0D0A202020203C54696D6520547970653D22537472696E67222056616C75653D2231363539353322202F3E0D0A202020203C44414720547970653D22537472696E67222056616C75653D2222202F3E0D0A202020203C43686B494420547970653D22537472696E67222056616C75653D2222202F3E0D0A202020203C466F726D5479706520547970653D22537472696E67222056616C75653D223122202F3E0D0A202020203C444220547970653D22537472696E67222056616C75653D22416C6C427573696E657373556E69747322202F3E0D0A202020203C46756E63494420547970653D22537472696E67222056616C75653D22534F4522202F3E0D0A202020203C53746174757320547970653D22537472696E67222056616C75653D2222202F3E0D0A202020203C46696C655479706520547970653D22537472696E67222056616C75653D2253464C22202F3E0D0A202020203C4465736372697074696F6E733E0D0A2020202020203C44656661756C7420547970653D22537472696E67222056616C75653D2253616C6573204F7264657220456E74727922202F3E0D0A2020202020203C4C303120547970653D22537472696E67222056616C75653D2253616C6573204F7264657220456E74727922202F3E0D0A2020202020203C4C333320547970653D22537472696E67222056616C75653D2253616973696520636F6D6D616E646520636C69656E7422202F3E0D0A2020202020203C4C333420547970653D22537472696E67222056616C75653D22456E747261646120646520C3B37264656E65732064652076656E746122202F3E0D0A2020202020203C4C333920547970653D22537472696E67222056616C75653D22496E736572696D656E746F206F7264696E652064692076656E6469746122202F3E0D0A2020202020203C4C343920547970653D22537472696E67222056616C75653D224175667472C3A4676520657266617373656E22202F3E0D0A2020202020203C4C353520547970653D22537472696E67222056616C75653D22456E74726164612064652070656469646F2064652076656E646122202F3E0D0A2020202020203C4C383120547970653D22537472696E67222056616C75653D22E58F97E6B3A8E382AAE383BCE38380E383BCE585A5E58A9B22202F3E0D0A2020202020203C4C383620547970653D22537472696E67222056616C75653D22E99480E594AEE8AEA2E58D95E5BD95E585A522202F3E0D0A2020202020203C4C383720547970653D22537472696E67222056616C75653D22E98AB7E594AEE8A882E596AEE98C84E585A522202F3E0D0A202020203C2F4465736372697074696F6E733E0D0A20203C2F4865616465723E0D0A20203C466F726D3E0D0A202020203C4372656174696F6E4C616E6720547970653D22537472696E67222056616C75653D223031222053464C4F6E6C793D223122202F3E0D0A202020203C416374696F6E733E0D0A2020202020203C5065726D697373696F6E73202F3E0D0A202020203C2F416374696F6E733E0D0A202020203C48656C70202F3E0D0A202020203C466F6E743E0D0A2020202020203C446566466F6E7453697A6520547970653D22496E7465676572222056616C75653D2238222053464C4F6E6C793D223122202F3E0D0A2020202020203C466F6E743E0D0A20202020202020203C4C616E677561676520547970653D22537472696E67222056616C75653D2244656661756C7422202F3E0D0A20202020202020203C466F6E744E616D6520547970653D22537472696E67222056616C75653D224D532053616E7320536572696622202F3E0D0A2020202020203C2F466F6E743E0D0A2020202020203C466F6E743E0D0A20202020202020203C4C616E677561676520547970653D22537472696E67222056616C75653D22383122202F3E0D0A20202020202020203C466F6E744E616D6520547970653D22537472696E67222056616C75653D224D5320554920476F7468696322202F3E0D0A2020202020203C2F466F6E743E0D0A202020203C2F466F6E743E0D0A202020203C436F6E74726F6C733E0D0A2020202020203C436F6E74726F6C3E0D0A20202020202020203C436F6E74726F6C5479706520547970653D22496E746567657222204644496E743D2231222056616C75653D223122202F3E0D0A20202020202020203C446973706C61795479706520547970653D22537472696E6722204644496E743D2230222056616C75653D22466F726D2057696E646F77222053464C4F6E6C793D223122202F3E0D0A20202020202020203C43617074696F6E20547970653D22537472696E6722204644496E743D2230222056616C75653D2253597C3F7C55547C3F7C3F3F3F3F3F3F22202F3E0DThe XML I posted so far is actually truncated as the full XML is quite big but I showed the beginning of it as this is the section I believe that is not being handled properly. Furthermore I am able to write the BLOB out to a file successfully without any errors using DBMS_LOB & UTL_FILE.PUT_RAW and this seems to handle the BOM without any issues but what I really need to do is read a single node in the XML and update it directly preferably using XMLTYPE directly with the BLOB.
    I would welcome your suggestions on how best to read a single node and update it when the XML is contained in a BLOB.
    Regards,
    Mohinder

  • How to Convert the content in BLOB field into a PDF file...

    Hi,
    I am having PDF files stored in BLOB column of a table in Oracle Database (11G R2).
    I want to retrieve the files back and store them in hard disk. I am successful in storing the content as a file with '.doc' but if I store the file as '.pdf', adobe fails to open the file with error
    Adobe Reader could not open file 'xxx.pdf' because it is either not a supported file type or because the file has been damaged (for example it was sent as an email attachment and wasn't correctly decoded)
    I am using following example code to achieve my goal...
    Declare
    b blob;
    c clob;
    buffer VARCHAR2(32767);
    buffer_size CONSTANT BINARY_INTEGER := 32767;
    amount BINARY_INTEGER;
    offset NUMBER(38);
    file_handle UTL_FILE.FILE_TYPE;
    begin
    select blob_data into b from blobdata where id=1;
    c := blob2clob(b);
    file_handle := UTL_FILE.FOPEN('BLOB2FILE','my_file.pdf','w',buffer_size);
         amount := buffer_size;
         offset := 1;
         WHILE amount >= buffer_size
         LOOP
              DBMS_LOB.READ(c,amount,offset,buffer);
              -- buffer:=replace(buffer,chr(13),'');
              offset := offset + amount;
              UTL_FILE.PUT(file_handle,buffer);
              UTL_FILE.FFLUSH(file_handle);
         END LOOP;
         UTL_FILE.FCLOSE(file_handle);
    end;
    create or replace FUNCTION BLOB2CLOB ( p_blob IN BLOB ) RETURN CLOB
    -- typecasts BLOB to CLOB (binary conversion)
    IS
    || Purpose : To Convert a BLOB File to CLOB File
    || INPUT : BLOB File
    || OUTPUT : CLOB File
    || History: MB V5.0 24.09.2007 RCMS00318572 Initial version
    ln_file_check NUMBER;
    ln_file_size NUMBER;
    v_text_file CLOB;
    v_binary_file BLOB;
    v_dest_offset INTEGER := 1;
    v_src_offset INTEGER := 1;
    v_warning INTEGER;
    lv_data CLOB;
    ln_length NUMBER;
    csid VARCHAR2(100) := DBMS_LOB.DEFAULT_CSID;
    V_LANG_CONTEXT NUMBER := DBMS_LOB.DEFAULT_LANG_CTX;
    BEGIN
    DBMS_LOB.createtemporary (v_text_file, TRUE);
    SELECT dbms_lob.getlength(p_blob) INTO ln_file_size FROM DUAL;
    DBMS_LOB.converttoclob (v_text_file, p_blob, ln_file_size, v_dest_offset, v_src_offset, 0, v_lang_context, v_warning);
    SELECT dbms_lob.getlength(v_text_file) INTO ln_length FROM DUAL;
    RETURN v_text_file;
    END;

    user755667 wrote:
    Hi,
    I am having PDF files stored in BLOB column of a table in Oracle Database (11G R2).
    I want to retrieve the files back and store them in hard disk. I am successful in storing the content as a file with '.doc' but if I store the file as '.pdf', adobe fails to open the file with error
    Adobe Reader could not open file 'xxx.pdf' because it is either not a supported file type or because the file has been damaged (for example it was sent as an email attachment and wasn't correctly decoded)
    I am using following example code to achieve my goal...
    Declare
    b blob;
    c clob;
    buffer VARCHAR2(32767);
    buffer_size CONSTANT BINARY_INTEGER := 32767;
    amount BINARY_INTEGER;
    offset NUMBER(38);
    file_handle UTL_FILE.FILE_TYPE;
    begin
    select blob_data into b from blobdata where id=1;
    c := blob2clob(b);
    file_handle := UTL_FILE.FOPEN('BLOB2FILE','my_file.pdf','w',buffer_size);
         amount := buffer_size;
         offset := 1;
         WHILE amount >= buffer_size
         LOOP
              DBMS_LOB.READ(c,amount,offset,buffer);
              -- buffer:=replace(buffer,chr(13),'');
              offset := offset + amount;
              UTL_FILE.PUT(file_handle,buffer);
              UTL_FILE.FFLUSH(file_handle);
         END LOOP;
         UTL_FILE.FCLOSE(file_handle);
    end;
    create or replace FUNCTION BLOB2CLOB ( p_blob IN BLOB ) RETURN CLOB
    -- typecasts BLOB to CLOB (binary conversion)
    IS
    || Purpose : To Convert a BLOB File to CLOB File
    || INPUT : BLOB File
    || OUTPUT : CLOB File
    || History: MB V5.0 24.09.2007 RCMS00318572 Initial version
    ln_file_check NUMBER;
    ln_file_size NUMBER;
    v_text_file CLOB;
    v_binary_file BLOB;
    v_dest_offset INTEGER := 1;
    v_src_offset INTEGER := 1;
    v_warning INTEGER;
    lv_data CLOB;
    ln_length NUMBER;
    csid VARCHAR2(100) := DBMS_LOB.DEFAULT_CSID;
    V_LANG_CONTEXT NUMBER := DBMS_LOB.DEFAULT_LANG_CTX;
    BEGIN
    DBMS_LOB.createtemporary (v_text_file, TRUE);
    SELECT dbms_lob.getlength(p_blob) INTO ln_file_size FROM DUAL;
    DBMS_LOB.converttoclob (v_text_file, p_blob, ln_file_size, v_dest_offset, v_src_offset, 0, v_lang_context, v_warning);
    SELECT dbms_lob.getlength(v_text_file) INTO ln_length FROM DUAL;
    RETURN v_text_file;
    END;I skimmed this and stopped reading when i saw the BLOB to CLOB function.
    You can't convert binary data into character based data.
    So very likely this is your problem.

  • How to convert BLOB into a String

    Hi,
    I got a blob column from the database.
    It contains one XML File.
    How to convert it into String.
    I need the code for how to convert the blob into String
    Thanks in Advance.

    A blob would be a byte-array, which you can use in the String(byte[]) constructor

Maybe you are looking for