CLOB to BLOB conversion to save space

Hi Gurus,
I am having a table with a CLOB column which I am asked to convert into BLOB and in the process save some space. But I am finding even after the conversion, it is taking same amount of space as the previous CLOB column.
Is there any way I can convert it to BLOB and/or save space in any way.
Please let me know if there are any ways.
Thanks
Amitava.

select * from v$version; -- it needs to be 11g+ Enterprise Edition;
select * from v$option where parameter='Advanced Compression';
But the best way, ask.  (on a piece of paper that requires a signature.)
MK

Similar Messages

  • How to call CLOB to BLOB conversion function within stored procedure?

    I have a tiny APEX application from which I need to be able to print. I’ve used these two resources: (Is there an inexpensive APEX report printer for invoices/checks/statements? and http://download.oracle.com/docs/cd/E14373_01/appdev.32/e13363/up_dn_files.htm#CJAHDJDA)
    I guess that in order to be able to download the RTF document stored in CLOB, I need to convert it into BLOB. I’ve found this function for this purpose on Oracle forums:
    CREATE OR REPLACE FUNCTION     c2b( c IN CLOB ) RETURN BLOB
    -- typecasts CLOB to BLOB (binary conversion)
    IS
              pos PLS_INTEGER := 1;
              buffer RAW( 32767 );
              res BLOB;
              lob_len PLS_INTEGER := DBMS_LOB.getLength( c );
    BEGIN
         DBMS_LOB.createTemporary( res, TRUE );
         DBMS_LOB.OPEN( res, DBMS_LOB.LOB_ReadWrite );
    LOOP
         buffer := UTL_RAW.cast_to_raw( DBMS_LOB.SUBSTR( c, 16000, pos ) );
         IF          UTL_RAW.LENGTH( buffer ) > 0
         THEN
                   DBMS_LOB.writeAppend( res, UTL_RAW.LENGTH( buffer ), buffer );
         END IF;
         pos := pos + 16000;
         EXIT WHEN pos > lob_len;
    END LOOP;
    RETURN res; -- res is OPEN here
    END c2b;And I am trying to use it in the modified download procedure that I also have found on Oracle forums:
    CREATE OR REPLACE PROCEDURE DOWNLOAD_WO(v_id IN NUMBER)
    AS
            v_mime          VARCHAR2(48);
            v_length     NUMBER;
            v_file_name     VARCHAR2(2000):= 'WO_Download.rtf';
            lob_loc          CLOB;
              v_blob      BLOB;
              v_company        jobs_vw.company%TYPE;
              v_project        jobs_vw.project%TYPE;
              v_description     jobs_vw.description%TYPE;
              v_date_          jobs_vw.date_%TYPE;
              v_job_no          jobs_vw.job_no%TYPE;
              v_apqwo               jobs_vw.apqwo%TYPE;
    --          v_mime           VARCHAR2(48) := 'application/msword';
    BEGIN
            SELECT     mime_type, report, DBMS_LOB.GETLENGTH(report)
              INTO     v_mime,lob_loc,v_length
              FROM     report_layouts
              WHERE     rl_id = 22332925279634283;
    -- JOB_VW record:
        SELECT     job_no
                   ,date_
                   ,description
                   ,apqwo
                   ,project
                   ,company       
         INTO     v_job_no
                   ,v_date_
                   ,v_description
                   ,v_apqwo
                   ,v_project
                   ,v_company
         FROM     jobs_vw
         WHERE     id = 214;
    -- Replace holders with actual values:
        lob_loc := REPLACE(lob_loc, '#COMPANY#', v_company);
        lob_loc := REPLACE(lob_loc, '#PROJECT#', v_project);
        lob_loc := REPLACE(lob_loc, '#DESCRIPTION#', v_description);
        lob_loc := REPLACE(lob_loc, '#DATE_#', TO_CHAR(v_date_, 'DD/MM/YYYY'));
        lob_loc := REPLACE(lob_loc, '#JOB_NO#', v_job_no);
        lob_loc := REPLACE(lob_loc, '#APQWO#', v_apqwo);
                  -- set up HTTP header
                        -- use an NVL around the mime type and
                        -- if it is a null set it to application/octect
                        -- application/octect may launch a download window from windows
                        owa_util.mime_header( nvl(v_mime,'application/octet'), FALSE );
                    -- set the size so the browser knows how much to download
                    htp.p('Content-length: ' || v_length);
                    -- the filename will be used by the browser if the users does a save as
                    htp.p('Content-Disposition:  attachment; filename="'||replace(replace(substr(v_file_name,instr(v_file_name,'/')+1),chr(10),null),chr(13),null)|| '"');
                    -- close the headers           
                    owa_util.http_header_close;
                    -- download the BLOB
    --                wpg_docload.download_file( Lob_loc );
                             v_blob := c2b(lob_loc);
                             wpg_docload.download_file( v_blob );
    end DOWNLOAD_WO;
    /Unfortunately when I try to compile the download_wo stored procedure I am getting this error:
    Error at line 64: PL/SQL: Statement ignoredThe 64th line is:
    v_blob := c2b(lob_loc);How should I correctly call c2b within download_wo? Any advice is greatly appreciated.
    Thank you for your time.
    Daniel

    Hello there,
    Well, its invalid :(
    Object C2B is Invalid. I didn't know since when I run the create ... function, I only get this feedback:
    Statement processed.
    0.19 secondsI am investigating.
    Daniel

  • Need Your advice on CLOB TO BLOB conversion.

    HI
    Edited by: 982229 on Jan 18, 2013 12:34 AM

    982229 wrote:
    Need you urgent help here.This is not a place for urgent help. Using the community discussion forums for urgent issues is a violation of the terms and conditions.
    http://www.oracle.com/html/terms.html
    >
    4. Use of Community Services
    Community Services are provided as a convenience to users and Oracle is not obligated to provide any technical support for, or participate in, Community Services. While Community Services may include information regarding Oracle products and services, including information from Oracle employees, they are not an official customer support channel for Oracle.
    You may use Community Services subject to the following: (a) Community Services may be used solely for your personal, informational, noncommercial purposes; (b) Content provided on or through Community Services may not be redistributed; and (c) personal data about other users may not be stored or collected except where expressly authorized by Oracle
    >
    Anything that is solely for your personal, informational, noncommercial purposes is not urgent.
    Please log a service request with support or hire a qualified consultant for urgent issues.
    http://www.google.com/search?q=oracle+consultant

  • BLOB-- CLOB-- BLOB conversion reducing length of BLOB

    Hi,
    I am using the following BLOB-->CLOB and CLOB-->BLOB conversion functions :
    CREATE OR REPLACE FUNCTION blob_to_clob (blob_in IN BLOB)
    RETURN CLOB
    AS
         v_clob CLOB;
         v_varchar RAW(32001);
         v_varchar1 VARCHAR2(32001);
         v_start     INTEGER := 1;
         v_buffer INTEGER := 32001;
    BEGIN
         DBMS_LOB.CREATETEMPORARY(v_clob, TRUE);
         FOR i IN 1..CEIL(DBMS_LOB.GETLENGTH(blob_in) / v_buffer)
         LOOP
         DBMS_LOB.READ(blob_in,v_buffer,v_start,v_varchar);
    DBMS_LOB.WRITEAPPEND(v_clob, utl_raw.length(v_varchar), v_varchar);
         v_start := v_start + v_buffer;
         END LOOP;
    RETURN v_clob;
    END blob_to_clob;
    CREATE OR REPLACE FUNCTION clob_to_blob (clob_in IN CLOB)
    RETURN BLOB
    AS
         v_blob BLOB;
         v_varchar RAW(32001);
         v_varchar1 RAW(32001);
         v_start     INTEGER := 1;
         v_buffer INTEGER := 32001;
    BEGIN
         DBMS_LOB.CREATETEMPORARY(v_blob, TRUE);
         FOR i IN 1..CEIL(DBMS_LOB.GETLENGTH(clob_in) / v_buffer)
         LOOP
         DBMS_LOB.READ(clob_in,v_buffer,v_start,v_varchar);
    DBMS_LOB.WRITEAPPEND(v_blob, utl_raw.length(v_varchar), v_varchar);
              v_start := v_start + v_buffer;
         END LOOP;
    RETURN v_blob;
    END clob_to_blob;
    I am using these functions to convert image files, stored as BLOB to CLOB for intermediate storage, and then converting them back to BLOB. In this process, I see a loss of information when the image is converted from CLOB to BLOB ...which is seen by using dbms_lob.getlength() .Using the following sql query:
    select dbms_lob.getlength(file_body),
    dbms_lob.getlength(blob_to_clob(file_body)),
         dbms_lob.getlength(clob_to_blob(blob_to_clob(file_body)))
    from my_table where image_id in (8819)
    i see that returned length is usually half in the 3rd column, i.e. for dbms_lob.getlength(clob_to_blob(blob_to_clob(file_body))). There is no change in length for 1st and 2nd columns. Could you please let me know why length is getting lost in the CLOB to BLOB conversion ? Thanks.

    Thanks for replying.
    This is required because we have to store images in ldt files using FNDLOAD, whiich only supports CLOB, not BLOB. I understand that images stored in binary formats should be stored in BLOB only, but I am exploring the possibility of converting BLOB format to CLOB and then back to BLOB without loss of information. Any pointers in this regard are appreciated. Thanks !

  • CLOB to NCLOB conversion in Oracle 9i

    Hi,
    I have a table with 8 million records. The table has a clob column that has to be converted in to a nclob column. I have writtten a procedure for the clob to nclob conversion using cursors and the limit functionality.The procedure is given as follows:
    CREATE OR REPLACE PROCEDURE pr_clob_to_nclob is
    TYPE type_dockey IS TABLE OF inf_doc_store.ds_doc_key%TYPE INDEX BY PLS_INTEGER;
    l_type_dockey type_dockey;
    TYPE type_rowid IS TABLE OF VARCHAR(100) INDEX BY PLS_INTEGER;
    l_type_rowid type_rowid;
    L_NUMERRORS NUMBER := 0;
    E_BULKINS_ILCHIS_EXCEPTION EXCEPTION;
    E_BULKINS_ELCHIS_EXCEPTION EXCEPTION;
    E_BULKINS_ILCTXN_EXCEPTION EXCEPTION;
    E_BULKINS_ELCTXN_EXCEPTION EXCEPTION;
    L_ERR_MESSAGE INF_ERROR_LOG.ERROR_TEXT%TYPE;
    L_FILE UTL_FILE.FILE_TYPE;
    CURSOR l_doc_store IS SELECT ds_doc_key,rowid from inf_doc_store where ds_doc_content1 is null;
    BEGIN
    --OPEN l_doc_store FOR 'select ds_doc_key,rowid from inf_doc_store1';
    OPEN l_doc_store;
    LOOP
    FETCH l_doc_store BULK COLLECT INTO l_type_dockey,l_type_rowid LIMIT 5000;
    BEGIN
    FORALL docidx IN 1 .. l_type_dockey.COUNT SAVE EXCEPTIONS
    UPDATE inf_doc_store SET DS_DOC_CONTENT1 = TO_NCLOB(DS_DOC_CONTENT)
    WHERE ROWID =l_type_rowid(docidx);
    EXCEPTION
    WHEN OTHERS THEN
    L_NUMERRORS := SQL%BULK_EXCEPTIONS.COUNT;
    FOR IDX IN 1 .. L_NUMERRORS LOOP
    L_ERR_MESSAGE := 'on bulk insert : Error in Doc key << ' ||
    l_type_dockey(IDX) || ' >> index << ' ||
    SQL%BULK_EXCEPTIONS(IDX)
    .ERROR_INDEX || ' IS ' ||
    SQLERRM(0 - SQL%BULK_EXCEPTIONS(IDX)
    .ERROR_CODE) || ' >>';
    PKG_INF_COMMON.PR_LOG_ERROR('CLOB_TO_NCLOB Migration',
    'inf_doc_store',
    L_ERR_MESSAGE,
    'NA');
    PKG_INF_COMMON.PR_UTL_PUTLINE(L_FILE,
    L_ERR_MESSAGE,
    'NA');
    END LOOP;
    PKG_INF_COMMON.PR_UTL_FCLOSE(L_FILE, 'inf_doc_store_updation');
    RAISE E_BULKINS_ILCHIS_EXCEPTION;
    END;
    COMMIT;
    EXIT WHEN l_doc_store%NOTFOUND;
    END LOOP;
    CLOSE l_doc_store;
    END pr_clob_to_nclob;
    The table in which the clob column is to be converted is inf_doc_header.
    The above procedure runs successfully but takes more than 48 hours to convert all the records.
    Can any body suggest me a way to optimise the procedure?
    Regards,
    Siddarth

    Hi,
    I have a table with 8 million records. The table has a clob column that has to be converted in to a nclob column. I have writtten a procedure for the clob to nclob conversion using cursors and the limit functionality.The procedure is given as follows:
    CREATE OR REPLACE PROCEDURE pr_clob_to_nclob is
    TYPE type_dockey IS TABLE OF inf_doc_store.ds_doc_key%TYPE INDEX BY PLS_INTEGER;
    l_type_dockey type_dockey;
    TYPE type_rowid IS TABLE OF VARCHAR(100) INDEX BY PLS_INTEGER;
    l_type_rowid type_rowid;
    L_NUMERRORS NUMBER := 0;
    E_BULKINS_ILCHIS_EXCEPTION EXCEPTION;
    E_BULKINS_ELCHIS_EXCEPTION EXCEPTION;
    E_BULKINS_ILCTXN_EXCEPTION EXCEPTION;
    E_BULKINS_ELCTXN_EXCEPTION EXCEPTION;
    L_ERR_MESSAGE INF_ERROR_LOG.ERROR_TEXT%TYPE;
    L_FILE UTL_FILE.FILE_TYPE;
    CURSOR l_doc_store IS SELECT ds_doc_key,rowid from inf_doc_store where ds_doc_content1 is null;
    BEGIN
    --OPEN l_doc_store FOR 'select ds_doc_key,rowid from inf_doc_store1';
    OPEN l_doc_store;
    LOOP
    FETCH l_doc_store BULK COLLECT INTO l_type_dockey,l_type_rowid LIMIT 5000;
    BEGIN
    FORALL docidx IN 1 .. l_type_dockey.COUNT SAVE EXCEPTIONS
    UPDATE inf_doc_store SET DS_DOC_CONTENT1 = TO_NCLOB(DS_DOC_CONTENT)
    WHERE ROWID =l_type_rowid(docidx);
    EXCEPTION
    WHEN OTHERS THEN
    L_NUMERRORS := SQL%BULK_EXCEPTIONS.COUNT;
    FOR IDX IN 1 .. L_NUMERRORS LOOP
    L_ERR_MESSAGE := 'on bulk insert : Error in Doc key << ' ||
    l_type_dockey(IDX) || ' >> index << ' ||
    SQL%BULK_EXCEPTIONS(IDX)
    .ERROR_INDEX || ' IS ' ||
    SQLERRM(0 - SQL%BULK_EXCEPTIONS(IDX)
    .ERROR_CODE) || ' >>';
    PKG_INF_COMMON.PR_LOG_ERROR('CLOB_TO_NCLOB Migration',
    'inf_doc_store',
    L_ERR_MESSAGE,
    'NA');
    PKG_INF_COMMON.PR_UTL_PUTLINE(L_FILE,
    L_ERR_MESSAGE,
    'NA');
    END LOOP;
    PKG_INF_COMMON.PR_UTL_FCLOSE(L_FILE, 'inf_doc_store_updation');
    RAISE E_BULKINS_ILCHIS_EXCEPTION;
    END;
    COMMIT;
    EXIT WHEN l_doc_store%NOTFOUND;
    END LOOP;
    CLOSE l_doc_store;
    END pr_clob_to_nclob;
    The table in which the clob column is to be converted is inf_doc_header.
    The above procedure runs successfully but takes more than 48 hours to convert all the records.
    Can any body suggest me a way to optimise the procedure?
    Regards,
    Siddarth

  • How to convert a CLOB to BLOB

    Hi,
    Can any one tell me how to convert a CLOB into BLOB? In Oracle 10g there is a function which is converttoblob(). But in Oracle 9i there is no function as such. If i am using Hextoraw() function still then its giving some pointer error. please let me know the solution.

    FUNCTION c2b( c IN CLOB ) RETURN BLOB
    -- typecasts CLOB to BLOB (binary conversion)
    IS
    pos PLS_INTEGER := 1;
    buffer RAW( 32767 );
    res BLOB;
    lob_len PLS_INTEGER := DBMS_LOB.getLength( c );
    BEGIN
    DBMS_LOB.createTemporary( res, TRUE );
    DBMS_LOB.OPEN( res, DBMS_LOB.LOB_ReadWrite );
    LOOP
    buffer := UTL_RAW.cast_to_raw( DBMS_LOB.SUBSTR( c, 16000, pos ) );
    IF UTL_RAW.LENGTH( buffer ) > 0 THEN
    DBMS_LOB.writeAppend( res, UTL_RAW.LENGTH( buffer ), buffer );
    END IF;
    pos := pos + 16000;
    EXIT WHEN pos > lob_len;
    END LOOP;
    RETURN res; -- res is OPEN here
    END c2b;

  • Converting CHAR or CLOB to BLOB in Oracle9i

    Hi!
    I want to convert CHAR or CLOB to BLOB.
    I am working with Oracle9i Database.
    Oracle9i Supplied PL/SQL Package Release 2 (9.2) does'nt support DBMS_LOB.CONVERTTOBLOB procedure.
    How I can convert CHAR or CLOB to BLOB in Oracle9i?
    Valery

    Hi Valery,
    For conversion to blob, just try the utl_raw package.
    I use utl_raw.cast_to_raw quite often.
    Or have a look at:
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:437819871174
    Good luck,
    Jan-Marcel

  • LOB : how convert CLOB into BLOB

    This code doesn't work : ORA-06502: PL/SQL: numeric or value error: hex to raw conversion error.
    declare
    vCLOB CLOB := empty_clob();
    vBLOB BLOB := empty_blob();
    begin
    dbms_lob.createTemporary(vCLOB,TRUE);
    dbms_lob.open(vCLOB, DBMS_LOB.LOB_READWRITE);
    -- Put data into CLOB
    l_length := dbms_lob.getlength(vCLOB);
    dbms_lob.read(vCLOB,l_length,1,buffer);
    dbms_lob.createTemporary(vBLOB,TRUE);
    dbms_lob.open(vBLOB, DBMS_LOB.LOB_READWRITE);
    dbms_lob.write(vBLOB,l_length,1,buffer);
    dbms_lob.close(vBLOB);
    dbms_lob.freeTemporary(vBLOB);
    dbms_lob.close(vCLOB);
    dbms_lob.freeTemporary(vCLOB);
    Thanks.

    You can use my procedure
    create or replace procedure CLOB2BLOB (p_clob in out nocopy clob, p_blob in out nocopy blob) is
    -- transforming CLOB &#226; BLOB
    l_off number default 1;
    l_amt number default 4096;
    l_offWrite number default 1;
    l_amtWrite number;
    l_str varchar2(4096 char);
    begin
    begin
    loop
    dbms_lob.read ( p_clob, l_amt, l_off, l_str );
    l_amtWrite := utl_raw.length ( utl_raw.cast_to_raw( l_str) );
    dbms_lob.write( p_blob, l_amtWrite, l_offWrite,
    utl_raw.cast_to_raw( l_str ) );
    l_offWrite := l_offWrite + l_amtWrite;
    l_off := l_off + l_amt;
    l_amt := 4096;
    end loop;
    exception
    when no_data_found then
    NULL;
    end;
    end;
    Best regards, Victor

  • I had all of my video files that I work on in iMovie saved to an external hard drive exclusively to save space on my Macbook.  I had just finalized a project, went to work on another one and files couldn't be found, were not deleted how do I find them?

    I had all of my video files that I work on in iMovie saved to an external hard drive exclusively to save space on my Macbook.  The other day I had just finalized a project and went to work on another one and when I opened the project I could see what should have been there, but scrolling over the entire clip I would only see black and that the file was missing.  I did not drag anything on the hard drive to the trash or move anything.  How can I get those files?  These are videos of my kids and I am devastated and willing to try anything!

    Control click does not work - no option to find files.  I have no idea what to do.  When I look at the usage of the external drive the space is being used, but I cannot find the files.  I am going to try MacKeeper's Undelete and see if I can make any progress with it. 

  • How can I "archive" mails in Mail App to another internal drive/partition to save space but still have it searchable in spotlight (and preferably visible, searchable, draggable in Mail App)?

    How can I "archive" mails in Mail App to another internal drive/partition to save space but still have it searchable in spotlight (and preferably visible, searchable, draggable in Mail App)?
    Background:
    I am using Mountain Lion and Mail App and running out of space on my small primary SSD drive (where I keep OS, apps, key user preferences/data and mail for speed). The mail data is the big variable (many GBs) and I want to "archive"/move some of the old mail to my 2nd drive inside the Mac. But I still want it searchable inside spotlight and preferably even inside Mail too. And I'd like to be able to still drag and drop old mails into this archive folder.
    What I've tried that seems to work:
    This seemed to work:
    1. Move the archive folder/mailbox to the 2nd drive/partition/folder (don't delete anything inside Mail App)
    2. Create a symbolic link from its new location to the original/old location
    This seems to work, it looks as "normal" and as if nothing happened inside Mail App but the folder now resides elsewhere and seems searchable etc. But I'm not sure that once caches refresh or over time with updates etc if stuff will break horribly or corrupt.
    Is that the right way to "archive" mails in Mail App to another internal drive/partition to save space but still have it searchable in spotlight and visible, searchable, draggable in Mail App?
    Thanks in advance!
    Cheers,
    Daniel

    I'm having a similar but slightly different problem. My company just migrated to Gmail, and it's saving mail drafts every 30 seconds into my Trash folder.
    I unchecked the "Show in IMAP" preference in the Gmail settings, but my Drafts folder completely disappeared. I went back and checked it and the folder reappeared (with my drafts still in there).
    I like the idea if starting an email on my laptop and having the option of finishing it on my iPhone or iPad, so only saving Drafts locally would not be ideal.

  • Can I delete or uninstall the old version of Firefox left on C: drive when I installed 4.0 on the F: drive to save space and not lose bookmarks or other info?

    Wanted to save space on C: drive and installed Firefox 4.0 on the F: drive. The new install did not delete the files of the older Firefox version in the C: drive. Is the 4.0 version in F: drive using any of the files left on the C: drive? Can I delete or uninstall the old version with out losing bookmarks or other vital information? I want to get the space back for the C: drive but don't want a big headache. When comparing file trees from the new install and the old, there were allot more files in the old and it made me afraid to delete or uninstall the old version.

    The version on the C drive can be deleted, it will not be used. The bookmarks, along with other user data, is stored in the profile folder which is in a different location than the application - http://kb.mozillazine.org/Profile_folder_-_Firefox
    There are more files in the old version, many of the files in the new version are placed inside omni.jar which is a compressed file.

  • I was going to install Rosetta Stone Spanish onto my Macbook but am concerned about it taking up space on my 2GB hard-drive.  I have an external WD hard-drive; is it possible to put the application onto the external hard-drive to save space on my mac?

    I was going to install Rosetta Stone Spanish onto my Macbook 10.6.7 but am concerned about it taking up space on my 2GB hard-drive.  I have an external WD hard-drive, and I was wondering if it is possible to put the application onto the external hard-drive to save space on my Mac? 

    I think you're confused about how much hard drive space you have.  You probably have 2 GB of RAM...  there hasn't been a Mac shipped with only a 2 GB hard drive in a while.  At the bottom of any Finder window, how much space is available?
    If you're actually running low on space, you should move documents to the external drive, since many applications want to be on the system drive.

  • 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

  • ?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?

  • How can I combine the nav bar and menu bar on the same line to save space?

    Firefox v29 seems to be a huge step backward in customization. I need to save space for content so previously I turned off tabs and combined the menu bar and nav bar on the same line. The url space is way too long anyway. Now with v29 all my customization is gone and I cannot get it back. I can no longer move items on the nav bar to combine it with the menu bar. Why was this done? It only limits my ability to customize my browser? I am very frustrated that you took a great browser and ruined it.

    I get it that Firefox has changed, but the change is for the worse. It makes it impossible to customize menus as I had before v.29.

Maybe you are looking for