Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

clob to blob at some instance fails with PL/SQL: numeric or value error: invalid LOB locator specifi

VivRichardsNov 20 2018 — edited Nov 22 2018

Hi

I am having  an existing function to convert clob to blob as below

  ---------------------------------------------------------------------------------------

  -- Function    : clob_to_blob

  -- Description : Converts CLOB to BLOB

  ---------------------------------------------------------------------------------------

  function clob_to_blob (p_clob in clob) return blob is

    vBlob        blob;

    vOffset      number default 1;

    vAmount      number default 4096;

    vOffsetWrite number default 1;

    vAmountWrite number;

    vBuffer      varchar2(4096);

    kProcedureName  constant varchar2(61) := kMyPackage||'.clob_to_blob';

  begin

    dbms_lob.createtemporary(vBlob, true);

    Begin

      loop

        dbms_lob.read(p_clob, vAmount, vOffset, vBuffer);

        vAmountWrite := utl_raw.length(utl_raw.cast_to_raw(vBuffer));

        dbms_lob.write(vBlob, vAmountWrite, vOffsetwrite, utl_raw.cast_to_raw(vBuffer));

        vOffsetWrite := vOffsetWrite + vAmountWrite;

        vOffset := vOffset + vAmount;

        vAmount := 4096;

      end loop;

    exception

      when no_data_found then

      null;

    end;

   

    return vBlob;

  exception

    when others then

      sysmsg.add_error_msg(sysmsg.g_event_id, kProcedureName, sqlerrm, sqlcode);

      sysmsg.add_alert_msg(sysmsg.g_event_id, kProcedureName,

                           'Unable to read CLOB (bytes read: '||vAmountWrite||', offset: '||vOffsetwrite||')');

      raise sysmsg.e_general_error;    

  end clob_to_blob;

At what instance can this fail with PL/SQL: numeric or value error: invalid LOB locator specified

Thanks

Comments
Post Details
Added on Nov 20 2018
12 comments
1,245 views