BASE64 (PDF) CLOB to BLOB

Hello everybody! I have to convert a BASE64 representation of a PDF file to BLOB. I found one example on the Internet but there is something wrong with it and I can't figure it out.
create or replace function decode_base64(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_encode.BASE64_DECODE(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 decode_base64;
The above procedure should work with files of any size (since there is a loop), but it only works when the PDF is smaller than 32 KB.

Just a guess.
You may have additional CRLFs added when encoding.
Try this:
create or replace function replaceClob (opCLob CLOB,cpReplaceStr VARCHAR2,cpReplaceWith VARCHAR2) RETURN CLOB IS
   cBuffer    VARCHAR2 (32767);
   nBuffer    BINARY_INTEGER := 32767;
   nStart     PLS_INTEGER := 1;
   nLen            PLS_INTEGER;
   oCRtn      CLOB := EMPTY_CLOB;
   BEGIN
     DBMS_LOB.CreateTemporary(oCRtn,TRUE);
     nLen := DBMS_LOB.GetLength(opCLob);
     WHILE nStart < nLen
     LOOP
       DBMS_LOB.Read(opCLob, nBuffer, nStart, cBuffer);
       IF cBuffer IS NOT NULL THEN
         cBuffer := REPLACE(cBuffer, cpReplaceStr, cpReplaceWith);
         DBMS_LOB.WriteAppend(oCRtn, LENGTH(cBuffer), cBuffer);
       END IF;
       nStart := nStart + nBuffer;
     END LOOP;
     RETURN oCRtn;
   END;and then add to your code:
create or replace function decode_base64(p_clob_in in clob) return blob is
       v_blob blob;
       v_offset integer;
       v_tem_clob clob;
       v_buffer_varchar varchar2(32000);
       v_buffer_raw raw(32000);
       v_buffer_size binary_integer := 32000;
       --v_buffer_size binary_integer := 3*1024;      
       begin
       if p_clob_in is null then
          return null;
       end if;
       -- Add this line
       v_tem_clob := replaceClob(p_clob_in,UTL_TCP.CRLF,'');
       dbms_lob.CREATETEMPORARY(v_blob, true);
       v_offset := 1;
       FOR i IN 1..CEIL(dbms_lob.GETLENGTH(v_tem_clob) / v_buffer_size) loop
           dbms_lob.READ(v_tem_clob, v_buffer_size, v_offset, v_buffer_varchar);          
           v_buffer_raw := utl_encode.BASE64_DECODE(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 decode_base64;Not tested.
HTH
Thomas

Similar Messages

  • Display a PDF returned as a base64 encoded clob from web service

    I'm trying to display a PDF document returned from a SOAP v1.1 web service. I'm able to return the XML into a collection using a process of type 'web service', but am struggling to display the document.
    This is the code I'm using to (attempt to) display the document, which doesn't return anything. If I exclude the clobbase642blob conversion an Adobe Reader pop-up appears, but I get an error message stating it is not a supported file type or the file has been damaged, which I would expect since it's a clob rather than a blob.
    DECLARE
      l_length    NUMBER;
      l_file_name VARCHAR2 (4000);
      l_file CLOB;
      l_blobfile BLOB;    
      l_ext VARCHAR2 (4000);
    BEGIN
      SELECT xtab."fileContent", xtab."fileName"
      INTO l_file, l_file_name
      FROM apex_collections c,
              XMLTable(XMLNAMESPACES(DEFAULT 'http://www.stellent.com/Payslip_Services/'),'//Payslip_Get_FileResponse/Payslip_Get_FileResult/downloadFile' passing xmltype001
                COLUMNS "fileContent" clob PATH 'fileContent'
                      , "fileName" PATH 'fileName'
              ) xtab
    where c.collection_name = 'P15_PAYSLIP_GET_FILE_RESULTS';
    l_blobfile := apex_web_service.clobbase642blob(l_file);
    l_length := DBMS_LOB.getlength(l_file);
      If INSTR (l_file_name, '.', -1, 1) > 0 then
          l_ext := SUBSTR (l_file_name, INSTR (l_file_name, '.', -1, 1) + 1);
      End if;
      IF (UPPER (l_ext) = 'PDF') THEN
        OWA_UTIL.mime_header ('application/pdf', FALSE);
      ELSIF (UPPER (l_ext) = 'DOC') THEN
        OWA_UTIL.mime_header ('application/msword', FALSE);
      ELSIF (UPPER (l_ext) = 'TXT') THEN
        OWA_UTIL.mime_header ('text/plain', FALSE);
      ELSIF (UPPER (l_ext) = 'HTML') THEN
        OWA_UTIL.mime_header ('text/html', FALSE);
      ELSE
        owa_util.mime_header('application/octet', FALSE );
      END IF;
      HTP.p ('Content-length: ' || l_length);
      HTP.p ( 'Content-Disposition: attachment; filename="' || l_file_name || '"' );
      OWA_UTIL.http_header_close;
      WPG_DOCLOAD.download_file (l_file);
    END;
    Apex 4.2.2
    Oracle 11g 11.2.0.1.0
    Any suggestions would be appreciated.
    Thanks,
    Graham

    What Adobe product is this a question for? This forum is for XML/API functionality for Adobe Connect. I'll move this question to the appropriate forum.

  • CLOB v BLOB?

    My customer wants to store a PDF in a database colomn...
    Which is better, CLOB or BLOB? Why?

    Why not just store the PDF in an o/s location andjust store a file reference on the database to keep
    things simple?
    But then you run the risk of losing the document one
    day since database backup and recovery will not be
    able to backup and restore this external reference.Indeed Kamal, and that's why I said it depends on the requirements. Can depend on many factors including where documents are originally stored and what backup strategy is in place for the servers etc. We'd have to look at the whole requirements, but that's out of scope of the original question here. ;)

  • Is it possible to pass PDF (stored as BLOB) to PDFDocMerger

    HI Folks.
    Will PDFDocMerger Class allow you to pass in multiple PDF BLOBs as an input Stream Array?
    Any pointers appreciated as I need to know if this is a non-starter.
    I have many invoice PDFs stored as BLOBs in my database. I need a user to be able to select a bunch of these and have BIP merge them into one document.
    Any help greatly appreciated.
    Many thanks
    Dogfighter

    Hello Ike.
    I have downloaded the IDE and I am following the installation steps.
    I have performed step 3 and I have the following questions.
    1) I can see a node in JDeveloper called XMLPublisherDataTemplate.java but not one named format template. Should I be able to? Also, could not find this in the IDE download folders. Where should I be looking.
    2) I have executed the 'Run' on the XMLPublisherUtility.java node. The result was...
    \j2sdk1.4.2_13\bin\java.exe -jar D:\NGC IT\Software\Oracle\Java Developer\jdev\lib\ojc.jar -source 1.3 -target 1.2 -noquiet -warn -nowarn:320 -nowarn:486 -nowarn:487 -deprecation:self -nowarn:560 -nowarn:704 -nowarn:489 -nowarn:415 -nowarn:909 -nowarn:412 -nowarn:414 -nowarn:561 -nowarn:376 -nowarn:371 -nowarn:558 -nowarn:375 -nowarn:413 -nowarn:377 -nowarn:372 -nowarn:557 -nowarn:556 -nowarn:559 -encoding Cp1252 -g -d C:\BIPublisherIDE\BIPublisherIDE\classes -make C:\BIPublisherIDE\BIPublisherIDE\classes\BIPublisherIDE.cdi -classpath "\j2sdk1.4.2_13\jre\lib\rt.jar;\j2sdk1.4.2_13\jre\lib\i18n.jar;\j2sdk1.4.2_13\jre\lib\sunrsasign.jar;\j2sdk1.4.2_13\jre\lib\jsse.jar;\j2sdk1.4.2_13\jre\lib\jce.jar;\j2sdk1.4.2_13\jre\lib\charsets.jar;\j2sdk1.4.2_13\jre\classes;C:\BIPublisherIDE\BIPublisherIDE\classes;C:\BIPublisherIDE\BIPublisherIDE\lib\collections.jar;C:\BIPublisherIDE\BIPublisherIDE\lib\i18nAPI_v3.jar;C:\BIPublisherIDE\BIPublisherIDE\lib\j5472959_xdo.zip;C:\BIPublisherIDE\BIPublisherIDE\lib\jdom.jar;C:\BIPublisherIDE\BIPublisherIDE\lib\versioninfo.jar;C:\BIPublisherIDE\BIPublisherIDE\lib\xdochartstyles.jar;C:\BIPublisherIDE\BIPublisherIDE\lib\xdoparser.jar;C:\BIPublisherIDE\BIPublisherIDE\lib\xmlparserv2-904.jar;D:\NGC IT\Software\Oracle\Java Developer\jdbc\lib\ojdbc14dms.jar;D:\NGC IT\Software\Oracle\Java Developer\jdbc\lib\orai18n.jar;D:\NGC IT\Software\Oracle\Java Developer\jdbc\lib\ocrs12.jar;D:\NGC IT\Software\Oracle\Java Developer\diagnostics\lib\ojdl.jar;D:\NGC IT\Software\Oracle\Java Developer\lib\dms.jar;D:\NGC IT\Software\Oracle\Java Developer\j2ee\home\lib\activation.jar;D:\NGC IT\Software\Oracle\Java Developer\j2ee\home\lib\ejb.jar;D:\NGC IT\Software\Oracle\Java Developer\j2ee\home\lib\jms.jar;D:\NGC IT\Software\Oracle\Java Developer\j2ee\home\lib\jta.jar;D:\NGC IT\Software\Oracle\Java Developer\j2ee\home\lib\mail.jar;D:\NGC IT\Software\Oracle\Java Developer\j2ee\home\lib\servlet.jar" -sourcepath C:\BIPublisherIDE\BIPublisherIDE\src;\j2sdk1.4.2_13\src.zip C:\BIPublisherIDE\BIPublisherIDE\src\bipublisher\api\XMLPublisherApi.java C:\BIPublisherIDE\BIPublisherIDE\src\bipublisher\api\XMLPublisherDataTemplate.java C:\BIPublisherIDE\BIPublisherIDE\src\bipublisher\api\XMLPublisherDelivery.java C:\BIPublisherIDE\BIPublisherIDE\src\bipublisher\config\XMLPublisherConfig.java C:\BIPublisherIDE\BIPublisherIDE\src\bipublisher\utility\XMLPublisherUtility.java
    Error: cannot read: java.lang.Object
    [11:07:06] Successful compilation: 0 errors, 0 warnings.
    Can you suggest why I get "Error: cannot read: java.lang.Object"
    Many thanks
    Simon

  • Problem displaying PDF stored in BLOB column

    Hello everyone.
    I've been trying to follow this tutorial http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::p11_question_id:232814159006 on displaying PDFs stored in BLOB columns. This is being performed on Apex 4.2, with my DB running 11g. I've got my procedure, which I'll post below:
    create or replace procedure "PDF" (p_id IN gvo_documents.doc_id%type)
    is
        l_lob    blob;
        l_amt    number default 30;
        l_off   number default 1;
        l_raw   raw(4096);
    begin
        select contents into l_lob
            from gvo_documents
             where doc_id = p_id;
    -- make sure to change this for your type!
        owa_util.mime_header( 'application/pdf' );
        begin
            loop
              dbms_lob.read( l_lob, l_amt, l_off, l_raw );
              htp.prn( utl_raw.cast_to_varchar2( l_raw ) );
              l_off := l_off+l_amt;
              l_amt := 4096;           
        end loop;
            exception
               when no_data_found then
                  NULL;
            end;
    end;
    I am trying to run this through a PL/SQL dynamic region and while I don't receive any error's, the content displayed is a huge mess of garbled text and odd characters. I've tried to run this procedure on numerous other document types, including word files and jpeg images, all with the necessary changes in my procedure, and regardless of what I use, I still get a large mess of strange characters. Does anyone have any information or ideas about why this is happening?

    If I understand correctly, your requirements needs to be broken down into two problems:
    1) click link that pops up a window displaying a new APEX page
    2) an APEX page the displays the document, not downloads it.
    I haven't done #1 (yet).
    However, you may be able to generate a URL that points to the new page as part of the SELECT statement for the Report.
    This has a related question, but no answer yet:
    open pdf in popup browser window
    The key is target="_blank" for the anchor tag.
    To generate the URL, you should use the APEX_UTIL.prepare_URL() function.
    If that doesn't work, a Dynamic Action that does some magical JavaScript stuff may be needed.
    For #2, I lost the URL that showed how to display a PDF as part of a "form" page.
    From what I remember:
    Start with a blank page with one blank HTML region (all the Items go in the HTML region)
    Add an Item for the PK/Doc_ID
    part I forgot Create a Data Manipulation Process
    - Automated Row Fetch
    - On Load - After Header
    - (stuff for your table/view)
    part I forgot Create an (I believe) "File Browser" item type. For Settings:
    - Storage Type "BLOB column specified in Item Source" (and place the column name of the BLOB there)
    - MIME Type Column: (column name) -- since you have multiple types, this is a MUST HAVE
    - Filename Column: (column name) -- I highly recommend you have this.
    - Content Disposition == INLINE <-- this is the kicker
    Also, you will need a Browser Plugin for each of the MIME Types (otherwise, the browser may try to 'download' the file)
    Browsers can handle Image types internally. Adobe's plugin can handle PDFs. I don't know about Word/Excel.
    Again, I don't remember the exact details, but that should cover most of it.
    MK

  • Opening a pdf from a blob

    Hi Guys,
    I know this is a borderline ApEx problem but I have a page whose sole job is to open a pdf from a blob stored in the database.
    This code works for most client machines:
    DECLARE
    l_blob blob;
    BEGIN
    SELECT letter INTO l_blob
    FROM letters
    WHERE lett_id = :P44_LETT_ID;
    -- owa_util.mime_header('application/pdf',false);
    -- tried pdf and octet they work the same?????
    owa_util.mime_header('application/octet',false);
    htp.p('Content-Length: ' || dbms_lob.getlength(l_blob));
    owa_util.http_header_close;      
    wpg_docload.download_file(l_blob);
    END;
    On some machines I get 'Windows cannot open this file ...File: f[7] ...To open this file..........
    On most machines this works fine.
    I haven't got it to fail with Firefox yet, just IE but only a few machines running IE. Client getting annoyed and I starting to stress.
    Many thanks
    Gary

    Have you already tried adding
    htp.p('Content-Disposition:  attachment; filename...as described here?
    http://download.oracle.com/docs/cd/B32472_01/doc/appdev.300/b32469/up_dn_files.htm#CIHDDJGF
    Maybe it solves the problem, in case IE is a little bit picky. But I really don't know.
    Patrick
    My APEX Blog: http://inside-apex.blogspot.com
    The ApexLib Framework: http://apexlib.sourceforge.net
    The APEX Builder Plugin: http://sourceforge.net/projects/apexplugin/

  • To upload a PDF file in BLOB column using Oracle Forms 9i

    Can anyone tell me how to upload a PDF file from client system using File dialog window and store its content in BLOB column in a table. The file to be uploaded will be in client side.

    Take a look at the following :
    Re: Storing a PDF in a BLOB
    Re: Retrive Image from DB into Image_item
    although the threads above are reffered to images and word doc... the procedure/steps are the same....
    Greetings...
    Sim

  • Uploading PDF in to BLOB and Retrieve PDF from BLOB

    hi
    I have recently started working in apex and run into a bump while trying to handle PDF file Attachments and BLOBs.
    I am trying to upload a PDF file into BLOB database Column using APEX, and later view this file from DB.
    I require assistance on how to upload PDF file into BLOB, and how i can later view this inside the browser window, using APEX
    thanks

    Maybe this blog post can help you.
    Regards,
    Sergio

  • ?Working with clob and blob - using Dbms_Lob

    I need to search through a blob and remove some of the data, but having problems working with dbms_lob.erase.
    Reading the documentation, the procedure is supposed to work with either blobs or clobs, but I can't get it to work with the blob.
    Here's what I've coded and it does not work correctly for blobs.
    What have I've done wrong?
    declare
    v_start                   integer;
    v_stop                    integer;
    v_amount                  integer;
    v_max_len                  integer:=32676;
    v_offset                   integer:=1;
    v_new_length               integer;
    v_clob clob;
    v_blob blob;
    begin
    update test_clob
    set clob_id = clob_id
    where clob_id = 1
    returning clob_desc into v_clob;
    v_start := 0;
    v_stop  := 0;
    v_amount := 0;
    v_start := dbms_lob.instr(v_clob, '<property name="Name">SortMode', v_offset );
    v_stop  := dbms_lob.instr(v_clob, '</property>',  v_start );
    v_amount := ((v_stop - v_start)+11) ;
    dbms_output.put_line('Clob: '||v_clob);
    dbms_lob.erase(v_clob, v_amount, v_start);
    dbms_output.put_line('Clob: '||v_clob);
    rollback;
    update test_clob
    set clob_id = clob_id
    where clob_id = 1
    returning blob_desc into v_blob;
    v_start := 0;
    v_stop  := 0;
    v_amount := 0;
    v_start := dbms_lob.instr(v_blob, utl_raw.cast_to_raw('<property name="Name">SortMode'), v_offset );
    v_stop  := dbms_lob.instr(v_blob, utl_raw.cast_to_raw('</property>'),  v_start );
    v_amount := ((v_stop - v_start)+11) ;
    dbms_output.put_line('Blob: '||utl_raw.cast_to_varchar2(v_blob) );
    dbms_lob.erase(v_blob, v_amount, v_start);
    dbms_output.put_line('Blob: '||utl_raw.cast_to_varchar2(v_blob) );
    rollback;
    end trg_bui_user_assoc_layout;
    /This is the output
    Clob: this is only a test <property name="Name">SortMode</property>  should leave this alone
    Clob: this is only a test                                            should leave this alone
    Blob: this is only a test <property name="Name">SortMode</property>  should leave this alone
    Blob: this is only a test

    Well, you left out the table DDL and your insert for sample data (would be nice to have) as well as your Oracle version (pretty much a necessity).
    Since i had to make my own there could be a difference in how you populated your table, but i can't reproduce your findings.
    ME_ORCL?drop table test_clob purge;
    Table dropped.
    Elapsed: 00:00:00.09
    ME_ORCL?
    ME_ORCL?create table test_clob
      2  (
      3     clob_id     number not null primary key,
      4     clob_desc   clob,
      5     blob_desc   blob
      6  );
    Table created.
    Elapsed: 00:00:00.03
    ME_ORCL?
    ME_ORCL?insert into test_clob values
      2  (
      3        1
      4     ,  'this is only a test <property name="Name">SortMode</property>  should leave this alone'
      5     ,  utl_raw.cast_to_raw('this is only a test <property name="Name">SortMode</property>  should leave this alone')
      6  );
    1 row created.
    Elapsed: 00:00:00.01
    ME_ORCL?
    ME_ORCL?commit;
    Commit complete.
    Elapsed: 00:00:00.01
    ME_ORCL?
    ME_ORCL?declare
      2  v_start                   integer;
      3  v_stop                    integer;
      4  v_amount                  integer;
      5  v_max_len                  integer:=32676;
      6  v_offset                   integer:=1;
      7  v_new_length               integer;
      8
      9  v_clob clob;
    10  v_blob blob;
    11
    12  begin
    13
    14   update test_clob
    15   set clob_id = clob_id
    16   where clob_id = 1
    17   returning clob_desc into v_clob;
    18
    19   v_start := 0;
    20   v_stop  := 0;
    21   v_amount := 0;
    22
    23   v_start := dbms_lob.instr(v_clob, '<property name="Name">SortMode', v_offset );
    24   v_stop  := dbms_lob.instr(v_clob, '</property>',  v_start );
    25   v_amount := ((v_stop - v_start)+11) ;
    26
    27   dbms_output.put_line('Clob: '||v_clob);
    28
    29   dbms_lob.erase(v_clob, v_amount, v_start);
    30
    31   dbms_output.put_line('Clob: '||v_clob);
    32
    33   rollback;
    34
    35   update test_clob
    36   set clob_id = clob_id
    37   where clob_id = 1
    38   returning blob_desc into v_blob;
    39
    40   v_start := 0;
    41   v_stop  := 0;
    42   v_amount := 0;
    43
    44   v_start := dbms_lob.instr(v_blob, utl_raw.cast_to_raw('<property name="Name">SortMode'), v_offset );
    45   v_stop  := dbms_lob.instr(v_blob, utl_raw.cast_to_raw('</property>'),  v_start );
    46   v_amount := ((v_stop - v_start)+11) ;
    47
    48   dbms_output.put_line('Blob: '||utl_raw.cast_to_varchar2(v_blob) );
    49
    50   dbms_lob.erase(v_blob, v_amount, v_start);
    51
    52   dbms_output.put_line('Blob: '||utl_raw.cast_to_varchar2(v_blob) );
    53
    54   rollback;
    55
    56  end trg_bui_user_assoc_layout;
    57  /
    Clob: this is only a test <property name="Name">SortMode</property>  should leave this alone
    Clob: this is only a test                                            should leave this alone
    Blob: this is only a test <property name="Name">SortMode</property>  should leave this alone
    Blob: this is only a test                                            should leave this alone
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.03
    ME_ORCL?select *
      2  from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production
    PL/SQL Release 11.2.0.2.0 - Production
    CORE    11.2.0.2.0      Production
    TNS for Linux: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production
    5 rows selected.
    Elapsed: 00:00:00.03
    ME_ORCL?

  • Stored PDF files with Blob

    I have being storing PDF files using Blob, but it is getting very time consuming to access these files again.
    Is there a better way of doing it? Is there a right way of doing it? I do not need to search inside the PDF, but I do need to access them either inside the Database or outside.
    Thank You for nay help

    I have a need to store PDF files that are documents that will complement process that my systems creates. And I need that those PDF files be accessible from inside my system, I do not need to search insede them because they will be stored by subject inside another subject, therefore whoever need the files will know were to find it, but to store and to access it is taking longer and longer as more files are added to the first thead.

  • Getting a PDF file in BLOB variable

    Hi Forum,
    I want to get a PDF file in BLOB variable from DB server.
    Further I will pass that variable to a procedure; in that procedure that variable will be inserted into a table.
    I have called procedure (inserting BLOB into a table) is ready.
    Can someone advice?
    thanks,
    regards.

    user573927 wrote:
    Hi Forum,
    I want to get a PDF file in BLOB variable from DB server.
    Further I will pass that variable to a procedure; in that procedure that variable will be inserted into a table.
    I have called procedure (inserting BLOB into a table) is ready.
    Can someone advice?It's all fine you saying what you want, but how about telling us what you've already done and where it's going wrong

  • Display a PDF from a BLOB Column on a page.

    Hi Folks.
    I have PDFs stored in BLOB columns in the database.
    Is there a way to display these to the APEX user on the page at runtime?
    Any pointers appreciated.
    Meantime I'm going to experiment.
    Cheers
    Dogfighter.

    I suppose this depends really on what you want.
    You have at least two choices.
    1) Allow the user to download the pdf and then they get the option to save it or open it in a new window
    2) You can also get them to open it. You can open it in a new window by adding "_blank"
    in the target.
    The sample application has procedures download_my_file and custom_image_display which will show you how to achieve this.
    The only other way you could possibly do it is open it as a plugin. Thats way beyond my knowledge, but I'm sure someone else will chip in.

  • Convert clob to blob

    Anyone know an easy way to convert clob data to blob data?
    We upgraded a client to 8.1.7.2 and now we can no longer store MS-Word templates to the RDBMS.
    I deduce this is because MS-Word templates are binary files.
    Earlier versions of 8.1.7 and 8.1.6 allowed us to do this. However, this is no longer the case.
    Some of my clob rows are over 6 meg.
    I have written some PL/SQL code to basically retrieve the clob data in cursor, loops through the clob in 32767 blocks,
    performing dbms_lob.substr, converts that data to hex(major pain), & then write the blocks using dbmbs_lob.write.
    I keep getting the proverbial "ORA-06502: PL/SQL: numeric or value error: invalid LOB locator specified: ORA-22275".
    Does anyone see flaws in my approach and might have an easier solution?
    Thanks!

    Here's my code:
    REATE OR REPLACE
    PROCEDURE p_load_clob_to_blob IS
    * Name:           p_load_clob_to_blob
    * Parameters: None
    * Purpose: This procedure loads the narr_blob column in the narr table_text with clob data from the
    * narr column.
    * Notes: This procedure assumes that narr table has been altered with narr_blob column added.
    * See the SQL below:
    *               alter table narr_text add (narr_blob blob);
    * Once this procedure executes, the table must altered to drop the narr_text clob column,
    * recreate the narr_text as blob, & then repopulate narr_text. See the SQL below:
    *                     alter table narr_text drop column narr;
    *                    alter table narr_text add (narr blob);
    *                    update narr_text set narr = narr_blob;
    *                    commit;
    * Called By: Sys Admin
    * CHANGE LOG
    * Changed By Date Change Description
    * EAO          01/16/02 Created.
    rec_read      INTEGER;
    rec_update      INTEGER;
    write_cnt INTEGER;
    write_amount BINARY_INTEGER;
    write_offset INTEGER;
    write_loop INTEGER;
    total_length      NUMBER;
    total_written      NUMBER;
    buffer VARCHAR2(32767);
    bbuffer RAW(32767);
    temp_narr_id NUMBER;
    max_loop               INTEGER;
    cx                    CLOB;
    bx                    BLOB;
    bx2                    BLOB;
    cur_evt               varchar2(50); -- current event
    v_err_descr          varchar2(256);
    i INTEGER;
    hex                    varchar(32767);
    CURSOR c_load_narr_clob IS
         SELECT narr, narr_id
         FROM narr_text
         where narr_id = 6366;
    BEGIN
    insert_event_log('', 'p_load_clob_to_blob', '', '', '', 'p_load_clob_to_blob started', '');
    rec_read := 0;
    rec_update := 0;
    ---Fill file
    insert_event_log('', 'p_load_clob_to_blob ','c_load_narr_clob ', '', 'S', 'c_narr_clob started', '');
    FOR csr IN c_load_narr_clob LOOP      
         cur_evt := 'Select narr from narr table: ';
         rec_read := rec_read + 1;
         write_loop := 1;
         write_cnt := 0;
         write_offset := 1;           
         total_written := 0;     
         cx := csr.narr;
    bx := empty_blob();          
         total_length := DBMS_LOB.GETLENGTH(cx);
         max_loop := (total_length / 32767) + 1;
         if (total_length <= 32767) THEN
              write_amount := total_length;
         ELSE
              write_amount := 32767;
         END IF;
    dbms_output.put_line('Length=' || to_char(total_length) || ' Max loop=' || to_char(max_loop) || ' Write Amount=' || to_char(write_amount));
         temp_narr_id := csr.narr_id;
         while write_cnt < max_loop
         loop
    --FOR write_loop in 1..max_loop LOOP
              delete temp_blob;
              delete temp_raw;
              commit;
              cur_evt := 'Dbms_lob.substr: ';
              dbms_output.put_line(cur_evt);
    buffer := DBMS_LOB.SUBSTR(cx, write_amount, write_offset);
              dbms_output.put_line('Write Amount='|| to_char(write_amount) || ' Write Offset=' || to_char(write_offset) );
    cur_evt := 'Hex to Raw Assigment: ';
              dbms_output.put_line(cur_evt);
              bbuffer := null;
              for i in 1..write_amount loop
                   hex := numtohex(ascii(substrb(buffer,i,1)));
                   bbuffer := bbuffer || hextoraw(hex);
              end loop;
    cur_evt := 'Insert temp_raw: ';
              dbms_output.put_line(cur_evt);
              insert into temp_raw(rx)
                   values (bbuffer);
              commit;
    cur_evt := 'Insert temp_blob: ';
              dbms_output.put_line(cur_evt);
              execute immediate 'insert into temp_blob(bx)
                   select TO_LOB(rx) from temp_raw';
              commit;
              cur_evt := 'Select bx2: ';
              dbms_output.put_line(cur_evt);
              bx2 := empty_blob();
              select bx into bx2 from temp_blob;
              cur_evt := 'Dbms_lob.append: ';
              dbms_output.put_line(cur_evt);
              dbms_lob.append(bx, bx2);
         dbms_output.put_line('Write Amount='|| to_char(write_amount) || ' Write Offset=' || to_char(write_offset) );
              write_offset := write_offset + write_amount;
              total_written := total_written + write_amount;
              write_cnt := write_cnt + 1;
              if (write_cnt = max_loop) then
              write_amount := total_length - total_written;
              end if;
    END LOOP;
    dbms_output.put_line('Total_written = ' || to_char(total_written) );
         cur_evt := 'Upd narr_blob in narr table: ';
         update narr_text
         set narr_blob = bx
         where narr_id = temp_narr_id;
         rec_update := rec_update + 1;
         commit;
    END LOOP;
    insert_event_log('', 'p_load_clob_to_blob ','c_load_narr_clob ', '', 'C', 'c_narr_clob completed', '');
    dbms_output.put_line('Records read=' || to_char(rec_read) || ' Records updated=' || to_char(rec_update) );
    insert_event_log('', 'p_load_clob_to_blob', '', '', '', 'p_load_clob_to_blob ended', '');
    EXCEPTION
         WHEN OTHERS THEN
         Rollback;
         v_err_descr := 'FATAL ERROR OCCURRED -'||cur_evt||sqlerrm;
         dbms_output.put_line (v_err_descr);
    END;
    FUNCTION numtohex(v_hex number) return varchar2
    is
    hex varchar2(4);
    num1 number;
    num2 number;
    begin
    num1 := trunc(v_hex/16);
    num2 := v_hex-(num1*16);
    if ( num1 >= 0 and num1 <= 9 ) then
    hex := hex||to_char(num1);
    end if;
    if num1 = 10 then hex := hex||'A'; end if;
    if num1 = 11 then hex := hex||'B'; end if;
    if num1 = 12 then hex := hex||'C'; end if;
    if num1 = 13 then hex := hex||'D'; end if;
    if num1 = 14 then hex := hex||'E'; end if;
    if num1 = 15 then hex := hex||'F'; end if;
    if ( num2 >= 0 and num2 <= 9 ) then
    hex := hex||to_char(num2);
    end if;
    if num2 = 10 then hex := hex||'A'; end if;
    if num2 = 11 then hex := hex||'B'; end if;
    if num2 = 12 then hex := hex||'C'; end if;
    if num2 = 13 then hex := hex||'D'; end if;
    if num2 = 14 then hex := hex||'E'; end if;
    if num2 = 15 then hex := hex||'F'; end if;
    return hex;
    end;

  • How we handle CLOB and BLOB Datatypes in HANA DB

    Dear HANA Gurus,
    We have would like to build EDW using HANA base on our source system Oracle and it's supports CLOB and BLOB datatypes
    Would you please suggest how do we handle in HANA DB.
    Let not say it's oracle specific.
    Regards,
    Manoj

    Hello,
    check SAP HANA SQL Reference Guide for list of data types:
    (page 14 - Classification of Data Types)
    https://service.sap.com/~sapidb/011000358700000604922011
    For this purpose might be useful following data types:
    Large Object (LOB) Types
    LOB (large objects) data types, CLOB, NCLOB and BLOB, are used to store a large amount of data such as text documents and images. The maximum size of an LOB is 2 GB.
    BLOB
    The BLOB data type is used to store large binary data.
    CLOB
    The CLOB data type is used to store large ASCII character data.
    NCLOB
    The NCLOB data type is used to store a large Unicode character object.
    Tomas

  • CLOB vs BLOB datatypes

    Which is the best datatype to use that will hold an input stream or byte stream, CLOB or BLOB?
    Thank you.

    Saber wrote:
    Which is the best datatype to use that will hold an input stream or byte stream, CLOB or BLOB?
    Thank you.CLOB is for character data ... so you'd want a BLOB.
    http://docs.oracle.com/cd/E11882_01/server.112/e26088/sql_elements001.htm#SQLRF50997

Maybe you are looking for

  • Firefox chrome in washed-out colors, hard to read

    Hi, To see anything but bright washed-out colors and text, I had to change to a dark theme! (NASA Night Launch) But this is as good as it gets, bleached pink (should be black), text still hard to read. - Web page ok, it's just the chrome (tabstip, ad

  • Size of Flex Application

    Is there a way to minimize the size of a Flex application. Just creating an mxml file with only an application tag creates a .swf gt 100k. Thanks! dustoff.

  • Web Cache Error

    We are occassionally getting the following error in various scenarios -- in development or just browsing the site: "Oracle Web Cache Network Error" Oracle Web Cache encountered a network error when communicating with the application web server. We ha

  • I need two tabbed panels on a page

    I have the tabbed panels widget working great but would like to have multiple panels on my page and it seems that will be hard to do given that the Java is called by a div id tag. Any one have any suggestions about how to make this work? Thanks, -TW

  • Can't get the "End Nested Style Here" function to work

    Hello, I have been testing a very simple nested style routine in InDesign CS3. It has a number with a period after it (and I have a character style named number), a single word followed by a colon (and I have a character style for that word and the c