using DBMS_LOB. LOADCLOBFROMFILE

Hi all
I had some difficulty in trying to use DBMS_LOB. LOADCLOBFROMFILE. Suppose I have this procedure that load an OS in a CLOB and read, however I get an error message saying that
ERROR at line 1:
ORA-22275: invalid LOB locator specified
ORA-06512: at "SYS.DBMS_LOB", line 890
ORA-06512: at "HR.SOME_PROC", line 14
ORA-06512: at line 1
This is the procedure:
create or replace procedure some_proc is
note_clob clob;
note_bfile bfile;
note_var varchar2(10000);
warning int;
dest_off int:=1;
src_off int:=1;
lang_ctx int:=0;
amount int:=dbms_lob.lobmaxsize;
begin
note_clob:=empty_clob();
note_bfile:=bfilename('TEMP_DIR','note.txt');
dbms_lob.fileopen(note_bfile);
dbms_lob.loadclobfromfile(note_clob,note_bfile,1000,dest_off,src_off,0,lang_ctx,warning);
--dbms_lob.read(note_clob,amount,1,note_var);
dbms_lob.fileclose(note_bfile);
--dbms_output.put_line(note_var);
end some_proc;
/
I comment on the part which reads and prints for debugging purposes. Could someone remind me where I did wrong on LOADCLOBFROMFILE?

Best regards
Val

Indicate below the line before loading into the target...

DBMS_LOB.CREATETEMPORARY(note_clob,true);

Tags: Database

Similar Questions

  • How to read bfile using dbms_lob.read and not raw characters

    Hi all
    Is it possible to read LOB using DBMS_LOB. READ so that the buffer is displayed in ASCII characters not BELIEVED. Suppose I have the following code:
    --create or replace procedure some_proc is
    declare
    note_clob clob;
    note_bfile bfile;
    note_var raw(10000);
    warning int;
    dest_off int:=1;
    src_off int:=1;
    lang_ctx int:=0;
    amount int:=1500;
    
    begin
    dbms_lob.createtemporary(note_clob,true);
    --note.txt is a text file
    note_bfile:=bfilename('TEMP_DIR','note.txt');
    
    dbms_lob.fileopen(note_bfile);
    dbms_lob.read(note_bfile,amount,1,note_var);
    dbms_lob.fileclose(note_bfile);
    dbms_output.put_line(to_char(note_var));
    
    end;
    /
    The DBMS_OUTPUT. Put_line shows the RAW data instead of its ASCII representation:
    53514C3E2073656C65637420696E7374616E63655F6E616D652C7374617475732C686F73745F6E616D652066726F6D207624
    696E7374616E63653B0D0A0D0A494E5354414E43455F4E414D45092053544154555320202020202020484F53545F4E414D45
    0D0A2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D202D2D2D2D2D2D2D2D2D2D2D2D202D2D2D2D2D2D2D2D2D2D0D0A696E61726109
    09204F50454E0920202020202066697265666C790D0A0D0A53514C3E2073656C656374202A2066726F6D2076247665727369
    6F6E3B0D0A0D0A42414E4E45520D0A2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D
    2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D0D0A4F7261
    636C652044617461626173652031316720456E74657270726973652045646974696F6E2052656C656173652031312E322E30
    2E312E30202D2036346269742050726F64756374696F6E0D0A504C2F53514C2052656C656173652031312E322E302E312E30
    202D2050726F64756374696F6E0D0A434F52450931312E322E302E312E300950726F64756374696F6E0D0A544E5320666F72
    204C696E75783A2056657273696F6E2031312E322E302E312E30202D2050726F64756374696F6E0D0A4E4C5352544C205665
    7273696F6E2031312E322E302E312E30202D2050726F64756374696F6E0D0A0D0A5B6F7261636C654066697265666C795D24
    206C736E7263746C207374617475730D0A0D0A4C534E5243544C20666F72204C696E75783A2056657273696F6E2031312E32
    2E302E312E30202D2050726F64756374696F6E206F6E2031332D4A554E2D323031312031363A30373A32330D0A0D0A436F70
    7972696768742028632920313939312C20323030392C204F7261636C652E2020416C6C207269676874732072657365727665
    642E0D0A0D0A436F6E6E656374696E6720746F20284445534352495054494F4E3D28414444524553533D2850524F544F434F
    4C3D49504329284B45593D45585450524F43313532312929290D0A535441545553206F6620746865204C495354454E45520D
    0A2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D0D0A416C696173202020202020202020202020202020202020
    2020204C495354454E45520D0A56657273696F6E20202020202020202020202020202020202020544E534C534E5220666F72
    204C696E75783A2056657273696F6E2031312E322E302E312E30202D2050726F64756374696F6E0D0A537461727420446174
    652020202020202020202020202020202031332D4A554E2D323031312031313A32393A35300D0A557074696D652020202020
    20202020202020202020202020202030206461797320342068722E203337206D696E2E203333207365630D0A547261636520
    4C6576656C2020202020202020202020202020206F66660D0A53656375726974792020202020202020202020202020202020
    204F4E3A204C6F63616C204F532041757468656E7469636174696F6E0D0A534E4D5020202020202020202020202020202020
    2020202020204F46460D0A4C697374656E657220506172616D657465722046696C652020202F7573722F6C6F63616C2F6F72
    61636C652F70726F647563742F31312E322E302F6462686F6D655F312F6E6574776F726B2F61646D696E2F6C697374656E65
    722E6F72610D0A4C697374656E6572204C6F672046696C652020202020202020202F7573722F6C6F63616C2F6F7261636C65
    2F646961672F746E736C736E722F66697265666C792F6C697374656E65722F616C6572742F6C6F672E786D6C0D0A4C697374
    656E696E6720456E64706F696E74732053756D6D6172792E2E2E0D0A2020284445534352495054494F4E3D28414444524553
    533D2850524F544F434F4C3D69706329284B45593D45585450524F43313532312929290D0A2020284445534352495054494F
    4E3D28414444524553533D2850524F544F434F4C3D7463702928484F53543D3132372E302E302E312928504F52543D313532
    Just curious to know if I can do this to DBMS_LOB. READ directly. Another way that I can do is use DBMS_LOB. LOADCLOBFROMFILE and not the DBMS_LOB. READ.

    Kind regards
    Val

    Hello
    Try this

      utl_raw.cast_to_varchar2(note_var)
    

    Edited by: user6806750 the 07.10.2011 01:59

  • ORA-43856 when using DBMS_LOB. FRAGMENT_DELETE

    BANNER
    Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    CORE Production 11.2.0.3.0
    AMT for Linux: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production

    We are pulling a CLOB value on a table and then trying to shave the first line using DBMS_LOB. FRAGMENT_DELETE. However, once reached this call, Oracle throws the error: ORA-43856: not supported for operation SECUREFILE LOB LOB type.

    I was unable to find anything on the web, although I see that Dan Morgan is facing problems with this call as well (Oracle 12 c DBMS_LOB demos).

    "Clearly there is a problem here so I open an SR to MOS (February 5, 2014) '

    I don't see any solution (or any what section of the knowledge base of SUPPORT. ORACLE.COM).

    Here is a code snippet:

    FUNCTION PROCESS_UPLOADED_FILE (ac_UploadedFileID IN SPAN_PARAMETER_WEB_UPLOAD. UPLOAD_ID % TYPE ( )

    RETURN VARCHAR2

    IS

    CURSOR lcsr_GetFilePayload IS

    SELECT FILE_PAYLOAD

    OF SPAN_PARAMETER_WEB_UPLOAD

    WHERE UPLOAD_ID = ac_UploadedFileID

    UPDATE OF THE FILE_PAYLOAD;

    lclb_FilePayload CLOB.

    ln_ReturnPos NUMBER: = - 1;

    ln_StartPos NUMBER: = 1;

    BEGIN

    OPEN lcsr_GetFilePayload.

    SEEK lcsr_GetFilePayload INTO lclb_FilePayload;

    CLOSE Lcsr_GetFilePayload;

    -Ignore the first line because it's a header

    ln_ReturnPos: = DBMS_LOB. InStr (lob_loc = > lclb_FilePayload,)

    model = > Chr (10),

    offset = > ln_StartPos)-1;

    ln_StartPos: = (ln_ReturnPos + 2);

    DBMS_LOB. FRAGMENT_DELETE (lclb_FilePayload, 1, ln_StartPos);

    -ERROR EXERCISE HERE

    ...

    END;

    Someone has some ideas (or workarounds)?

    Thank you

    -Joe

    We are pulling a CLOB value on a table and then trying to shave the first line using DBMS_LOB. FRAGMENT_DELETE. However, once reached this call, Oracle throws the error: ORA-43856: not supported for operation SECUREFILE LOB LOB type.

    The error seems clear enough to me.

    You can perform operations of FRAGMENT if the CLOB using no storage SECUREFILE.

    By default, LOB columns are created as BASICFILE LOB.

    You are most likely in this case. You can check for your table using, for example, DBMS_METADATA. GET_DDL.

    Example of work using SECUREFILE:

    SQL > create table (test_clob)

    integer id 2

    3, doc clob

    4)

    craft store 5 (doc) as navigation;

    Table created.

    SQL > insert into test_clob values (1, to_clob ('head' |)) Chr (10) | ((' ABC'));

    1 row inserted.

    SQL > commit;

    Validation complete.

    SQL > select doc from test_clob where id = 1;

    DOC

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

    head

    ABC

    SQL >

    SQL > declare

    2

    slider 3 c is

    4. Select doc

    test_clob 5

    6 where id = 1

    7 for the update;

    8

    9 v_doc clob.

    number of 10 v_returnpos: = - 1;

    Number 11 v_startpos: = 1;

    12

    13. begin

    14

    Open from 15 c;

    16 fetch c into v_doc;

    17 close c;

    18

    19. ignore the first line because it's a header

    20 v_returnpos: = dbms_lob.instr (lob_loc-online v_doc

    21, model-online Chr (10)

    22, offset-online v_startpos).

    23

    24 dbms_lob.fragment_delete (v_doc, v_returnpos, 1);

    25

    26 end;

    27.

    PL/SQL procedure successfully completed.

    SQL > select doc from test_clob where id = 1;

    DOC

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

    ABC

    Is therefore:

    -Re-create the table using SECUREFILE (needs a time out)

    -migrate columns LOB using DBMS_REDEFINITION

    Or, if you cannot perform all these operations, the solution is to copy the data after the first line in an another CLOB and to update the table with the new.

  • ORA-22288 using dbms_lob.open

    Hello

    I try to store files in a table with a column of type BLOB.

    I use this procedure:

    CREATE OR REPLACE procedure EBISDOKUMENTE.datei_einfuegen (v_directory varchar2, v_quelldatei varchar2)
    is
      v_quell_lob  bfile := bfilename(v_directory, v_quelldatei);
      v_ziel_lob   blob;
      v_id         number;
      v_groesse    number;
      
    begin
      select seq_dokument.nextval into v_id from dual;
      select dbms_lob.getlength(v_quell_lob) into v_groesse from dual;
    
      insert into dokument (id, inhalt)
      values (v_id, empty_blob())
      returning inhalt into v_ziel_lob;
      
      dbms_lob.open(v_quell_lob, dbms_lob.lob_readonly);
    
      dbms_lob.loadfromfile(dest_lob => v_ziel_lob,
                                src_lob  => v_quell_lob,
                                amount   => v_groesse);
    
      dbms_lob.close(v_quell_lob);
    
      commit;
    end;
    

    If I run the procedure with

    begin
      datei_einfuegen('EBISDOKUMENTE', '1234.dat');
    end;
    

    I got an ORA-22288 the dbms_log.open of the line.

    I first thought that there is a problem with the file or directory (authorization and so on), but the statement

    select dbms_lob.getlength(v_quell_lob) into v_groesse from dual;
    

    succeeds and returns to the good size of the file. So this should not be a permission problem.

    Any ideas, what is the problem?

    Kind regards

    Mark

    http://docs.Oracle.com/CD/E11882_01/Relnotes.112/e23557/TOC.htm#CJAEJECJ

  • Exception during the update of a value of clob using dbms_lob.fragment_insert

    Hello
    This is the query
    procedure tempProc (str3 in varchar2) is
    CLOB QI;
    -LOB (QI) STORE DO securefile;
    v_cursor refcursor;
    Str varchar2 (50);
    i the number '30' default;
    Start
    Open v_cursor for select b.OCEAN_RATE_XML.getClobVal (B TNMAB_OCEAN_RATE_XML)
    WHERE (XMLCast (XMLQuery (' declare default element namespace "http://com.oocl.schema.tnm.agreementbuilder";))) ( :  :) ObjectID/OceanOfferRate /'
    PASSING B.OCEAN_RATE_XML REFERRING CONTENT) AS NUMBER (20))) = 200000000000050;
    extract v_cursor in IQ;
    close v_cursor;
    dbms_output.put_line ('ABCD' |) DBMS_LOB. GetLength (QI));
    DBMS_LOB.fragment_insert (QI, 3, DBMS_LOB.getlength (QI) - 17, "< abc / > '");
    dbms_output.put_line (' ' inserted ');
    DBMS_LOB. READ (QI, I, DBMS_LOB.getlength (QI) - I, str);
    -DBMS_LOB. Read (QI, 20, DBMS_LOB. GetLength (QI) - 20, STR);
    dbms_output.put_line ('jobs read');
    dbms_output.put_line (STR);


    end tempProc;

    I get the exceptionError report below:

    ORA-43856: LOB unsupported type for operation SECUREFILE LOB
    ORA-06512: at "SYS." DBMS_LOB", line 1076
    ORA-06512: at "TNM_PLSQL. TNM_AB_QI_UPDT_PKG', line 377
    ORA-06512: at line 5
    ORA-06512: at line 9 level

    < OceanOfferRate xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" container = "http://www.w3.org/2001/XMLSchema" xmlns = "http://com.oocl.schema.tnm.agreementbuilder" >
    < ObjectID > 200000000000050 < / ObjectID >
    < RateID > 2 < / RateID >
    < > 00000002 AgreementID < / AgreementID >
    < StartingVersion > 0 < / StartingVersion >
    < EndingVersion > 0 < / EndingVersion >
    < EffectiveFrom > 2010-05-16T 00: 00:00.000000 < / EffectiveFrom >
    < EffectiveTo > 2010-06-30T 00: 00:00.000000 < / EffectiveTo >
    < RateStatus > QuoteExpired < / RateStatus >
    Approved < ApprovalStatus > < / ApprovalStatus >
    < flags > 3 < / Flags >
    < rates > 015 < / rates >
    < BaseRates >
    20GP < SizeType > < / SizeType >
    < amount > 65 < / amount >
    < currency > $ < / currency >
    < EffectiveFrom > 2010-05-16T 00: 00:00.000000 < / EffectiveFrom >
    < EffectiveTo > 2010-06-30T 00: 00:00.000000 < / EffectiveTo >
    < flags > 0 < / Flags >
    < / BaseRates >
    < BaseRates >
    40GP < SizeType > < / SizeType >
    < amount > 100 < / amount >
    < currency > $ < / currency >
    < EffectiveFrom > 2010-05-16T 00: 00:00.000000 < / EffectiveFrom >
    < EffectiveTo > 2010-06-30T 00: 00:00.000000 < / EffectiveTo >
    < flags > 0 < / Flags >
    < / BaseRates >
    < BaseRates >
    40HQ < SizeType > < / SizeType >
    < amount > 100 < / amount >
    < currency > $ < / currency >
    < EffectiveFrom > 2010-05-16T 00: 00:00.000000 < / EffectiveFrom >
    < EffectiveTo > 2010-06-30T 00: 00:00.000000 < / EffectiveTo >
    < flags > 0 < / Flags >
    < / BaseRates >
    default < ShippingPartyGroupName > < / ShippingPartyGroupName >
    default < CustomerContactGroupName > < / CustomerContactGroupName >
    default < NamedCustomerGroupName > < / NamedCustomerGroupName >
    < LastSentDate > 2010-06-14T 22: 42:48.536000 < / LastSentDate >
    < ValidityDays > 30 < / ValidityDays >
    < ValidityExpirationDate > 2010-06-30T 00: 00:00.000000 < / ValidityExpirationDate >
    < GuidelineRateReference >
    < trunk >
    < RateID > 100001510668470 < / RateID >
    < SurchargeIDs > 684172719752758 < / SurchargeIDs >
    < SurchargeIDs > 626856918161564 < / SurchargeIDs >
    < SurchargeIDs > 680028613161439 < / SurchargeIDs >
    < SurchargeIDs > 679555629913553 < / SurchargeIDs >
    < SurchargeIDs > 673382151283681 < / SurchargeIDs >
    < SurchargeIDs > 679789705628181 < / SurchargeIDs >
    < SurchargeIDs > 653835218283772 < / SurchargeIDs >
    < SurchargeIDs > 653955477367768 < / SurchargeIDs >
    < SurchargeIDs > 653955477367759 < / SurchargeIDs >
    < / trunk >
    < / GuidelineRateReference >
    < CreatedOn > 2010-05-16T 13: 40:29.201344 < / CreatedOn >
    < CreatedBy > KRISHSA < / CreatedBy >
    < vendor > COOKBR < / seller >
    < BureauVentes > PHE < / BureauVentes >
    < LastUpdated > 2010-06-30T 00: 13:06.000000 < / LastUpdated >
    < LastUpdatedBy > TNM_APPLN < / LastUpdatedBy >
    < origins >
    < ID_Wrappers >
    < value > 100000000026067 < / value >
    < / ID_Wrappers >
    < ID_Wrappers >
    < value > 100000000008923 < / value >
    < / ID_Wrappers >
    < ID_Wrappers >
    < value > 100000000024173 < / value >
    < / ID_Wrappers >
    < / origins >
    < destination >
    < ID_Wrappers >
    < value > 100000000008923 < / value >
    < / ID_Wrappers >
    < ID_Wrappers >
    < value > 100000000024173 < / value >
    < / ID_Wrappers >
    < ID_Wrappers >
    < value > 100000000013006 < / value >
    < / ID_Wrappers >
    < ID_Wrappers >
    < value > 100000000046704 < / value >
    < / ID_Wrappers >
    < / destination >
    < DeliveryMode > YY < / DeliveryMode >
    < TradeLane > IAT < / TradeLane >
    < product >
    < description > cotton for test < / Description >
    < CargoNatureGroup > 32 < / CargoNatureGroup >
    < / product >
    < RateLevel > 1 < / RateLevel >
    < / OceanOfferRate >

    An adviser if there is other ways to update the clob with additional information at the end of the XML file before < / OceanOfferRate >?

    Hello

    Funny approach ;)

    I'm sure that you will find this more easy and much more supported:

    SELECT appendChildXML( ocean_rate_xml
                         , '/OceanOfferRate'
                         , xmltype('')
                         , 'xmlns="http://com.oocl.schema.tnm.agreementbuilder"' )
    FROM tnmab_ocean_rate_xml
    WHERE XMLCast(
            XMLQuery('declare default element namespace "http://com.oocl.schema.tnm.agreementbuilder"; /OceanOfferRate/ObjectID'
                     PASSING ocean_rate_xml RETURNING CONTENT)
            AS NUMBER(20)
          ) = 200000000000050
    ;
    

    If your real goal is to update the column back, then you can do in a single statement:

    UPDATE tnmab_ocean_rate_xml
    SET ocean_rate_xml =
           appendChildXML( ocean_rate_xml
                         , '/OceanOfferRate'
                         , xmltype('')
                         , 'xmlns="http://com.oocl.schema.tnm.agreementbuilder"' )
    WHERE ...
    ;
    

    (BTW, to serialize the document use XMLSerialize rather than the old method of getClobVal function.)

    In addition, new in version 11.2.0.3:

    SELECT XMLQuery(
            'declare default element namespace "http://com.oocl.schema.tnm.agreementbuilder"; (: :)
             copy $d := /OceanOfferRate modify ( insert node  as last into $d ) return $d'
            passing ocean_rate_xml
            returning content
           )
    FROM tnmab_ocean_rate_xml
    WHERE ...
    

    Published by: odie_63 on Dec 19. 2011 21:30 - added update of XQuery example

  • How to load an image using DBMS_LOB

    I've never used the DBMS_LOB and I tried to write this stored procedure for reading an image from the Unix server file and put it in a table, but I get an error.

    CREATE TABLE marco_x_lob (nome varchar2 (10))
    Immagine BLOB)
    LOB (immagine) STORE AS
    (TABLESPACE MEDIUM_LOB
    STORAGE (INITIAL 5 M DEPENDING ON 5 M))
    TABLESPACE SMALL_TBL
    storage (initial 100 next K 100K pctincrease 0);

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

    CREATE OR REPLACE PROCEDURE load_marco_x_lob IS

    src_file BFILE: = ' / users/image.jpg ';
    dst_file BLOB;
    lgh_file directory.

    Start

    -Open the file
    DBMS_LOB. FileOpen (src_file, dbms_lob.file_readonly);

    -determine the length
    lgh_file: = dbms_lob.getlength (src_file);

    -Read the file
    DBMS_LOB. LoadFromFile (dst_file, src_file, lgh_file);

    -update the blob field
    Update marco_x_lob
    value = "logo" Nome
    Immagine = dst_file;

    -close file
    DBMS_LOB. FileClose (src_file);

    end load_marco_x_lob;
    /

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

    When I try to compile the above stored procedure I get "error: PLS 00382: expression is of the wrong type line: text 3: src_file BFILE: = ' / users/formazpr/prove_lob/piemlav.jpg';

    Could you help me to use correctly the DBMS_LOB? I've got Oravle 8.1.7
    Thank you.

    You must create a database directory, pointing to/users/test_lob.

    CREATE DIRECTORY mydir AS '/users/test_lob';
    

    http://download.Oracle.com/docs/CD/E11882_01/server.112/e10592/statements_5007.htm#SQLRF01207
    and use it.

  • ? Work with clob and blob - using Dbms_Lob

    I need to look into a blob and to delete some data, but having problems to work on dbms_lob.erase.
    Reading the documentation, the procedure is supposed to work with BLOB or CLOB, but I can't make it work with the blob.

    Here's what I coded and it does not work for blobs.

    What 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 DDL table and your insert for the sample data (would be nice to have) as well as your version of Oracle (practically a necessity).

    Since I had to make my own that there could be a difference in how you filled your table, but I can not 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 SortMode  should leave this alone'
      5     ,  utl_raw.cast_to_raw('this is only a test SortMode  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, 'SortMode', v_offset );
     24   v_stop  := dbms_lob.instr(v_clob, '',  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('SortMode'), v_offset );
     45   v_stop  := dbms_lob.instr(v_blob, utl_raw.cast_to_raw(''),  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 SortMode  should leave this alone
    Clob: this is only a test                                            should leave this alone
    Blob: this is only a test SortMode  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?
    
  • Problem with my Base64 Encoding Routine CLOB.

    I wrote a program that reads an xml file in the database
    and makes Base64encoded.

    We must work on 10g and above

    If the length specified in the code below reading is greater than the length of the xml_file, and then I get the result (output) expected.

    However if the playback time is less than the length of the file, then I get a lot of "is" in the file and, therefore, invalid, which means that the file is not readable by the application of encoding.
    I'm sure I read the lengths of blob correctly, and the problem is somehow related to base64 encoding. Any help appreciated
    [create or replace profile_dir as &profile_dir;
    create global temporary table load_xml
    (profile_text clob)
    on commit delete rows;
    
    create or replace
    procedure encode_xml_clobs(p_file_in  in varchar2,
                                 p_clob_out out nocopy clob )
     as
     pragma autonomous_transaction;
        dest_clob   CLOB;
        src_clob    BFILE  := BFILENAME('PROFILE_DIR', p_file_in);
        dst_offset  number := 1 ;
        src_offset  number := 1 ;
        lang_ctx    number := DBMS_LOB.DEFAULT_LANG_CTX;
        warning     number;
    ------------
    -- processing declarations for encoding base64 --
    v_xml_string varchar2(32767);
    v_string varchar2(32767);
    v_start_pos number := 0;
    v_read_length number := 1000;
    v_final_start_pos number;
    v_clob_length number;
    type clob_array_type is table of clob index by binary_integer;
    clob_array clob_array_type;
    v_index number :=0;
    -- Declarations for converting base64encoded string to a clob
    v_encoded_length number;
    v_temp_clob clob;
    BEGIN
        -- -----------------------------------------------------------------------
        -- THE FOLLOWING BLOCK OF CODE WILL ATTEMPT TO INSERT / WRITE THE CONTENTS
        -- OF AN XML FILE TO A CLOB COLUMN. IN THIS CASE, WE WILL USE THE NEW 
        -- DBMS_LOB.LoadCLOBFromFile() API WHICH *DOES* SUPPORT MULTI-BYTE
        -- CHARACTER SET DATA.
        -- -----------------------------------------------------------------------
    -- load_xml should be a  Global temporary table with on commit delete rows 
        INSERT INTO load_xml(profile_text) 
            VALUES( empty_clob())
            RETURNING profile_text INTO dest_clob;
    
        -- -------------------------------------
        -- OPENING THE SOURCE BFILE IS MANDATORY
        -- -------------------------------------
        DBMS_LOB.OPEN(src_clob, DBMS_LOB.LOB_READONLY);
    
        DBMS_LOB.LoadCLOBFromFile(
              DEST_LOB     => dest_clob
            , SRC_BFILE    => src_clob
            , AMOUNT       => DBMS_LOB.GETLENGTH(src_clob)
            , DEST_OFFSET  => dst_offset
            , SRC_OFFSET   => src_offset
            , BFILE_CSID   => DBMS_LOB.DEFAULT_CSID
            , LANG_CONTEXT => lang_ctx
            , WARNING      => warning
        );
        DBMS_LOB.CLOSE(src_clob);
    --    DBMS_OUTPUT.PUT_LINE('Loaded XML File using DBMS_LOB.LoadCLOBFromFile: (ID=1');
    -- file now successfully loaded
    
    select dbms_lob.GETLENGTH(profile_text)
    into v_clob_length 
    from load_xml;
    -- File now loaded in temporary table
    -- we now need to take the clob , convert it to varchar2
    v_read_length :=64;
    v_xml_string := '';
    while v_start_pos <=  v_clob_length
    loop
    v_index := v_index + 1;
    v_string := '';
    --dbms_output.put_line('Start_pos=>'||(v_start_pos+1)||' Read Length=>'||v_read_length);
    --encode base64 
    select utl_raw.cast_to_varchar2(
    utl_encode.base64_encode(
    utl_raw.cast_to_raw(dbms_lob.substr(profile_text,least(v_read_length,v_clob_length-v_start_pos),v_start_pos+1))
    ))
      into v_string
      from load_xml;
    --dbms_output.put_line(v_string);
    v_start_pos  := v_start_pos+v_read_length;
    clob_array(v_index) := v_string;
    end loop;
    p_clob_out := clob_array(1);
    for i in 2 .. v_index
    loop
    dbms_lob.append(p_clob_out,clob_array(i));
    end loop;
    commit;
    END;

    Base64 encoding encodes each 3 bytes of input data in the 4 bytes of output data. She uses the equal signs to indicate nodata and at the end of the coded sequence. Try chaning your v_read_length setting to a multiple of 3 e.g. 960 or 1008 instead of the current 1000. I use multiples of 48 because the utl_encode.base64_encode function adds a linebreak for every 48 bytes of input data (64 bytes of output). If you use a value that is not divisible by 48, you will always get a legitimate coding, since it is divisible by 3, but you'll get a few lines more than others when you add them together.

  • Need help in the use of dbms_lob.read

    I need to upload a file in an Oracle table to a Blob column. The name of the file with the contents of the file are all in a BLOB column.

    Once it's done, I need to read the file and extract the contents of the file and load it into an intermediate table.

    Downloaded file is a. CSV file.



    For example, the. CSV file is: ABC.csv file and its contents will look like:

    1, Hello, Nisha

    2, Hello, happy

    3, bye, Rahul

    Etc...



    This is why the table containing the BLOB column will contain:

    Creation_date file

    ABC.csv 09/11/2009



    How can I read a file from the BLOB and upload column in an intermediate table?



    Final staging table should look like:

    Record number welcome name

    1 Hello Nisha

    2 happy salvation

    Rahul 3 bye



    I think I'm supposed to use dbms_lob.read, but I'm not really sure how to use it. If there is any script, please mail me the same.



    Thank you...

    But for my needs, I multiiple users downloading the same file in the table of the BLOB.

    It's just worse and worse.

    You can do this asynchronously - have a background process download the CSV file and insert into the destination table. Depends on if your users want to see the results immediately. You can also have your users load the OS, insert it into the destination table, and then in the blob store.

    Information on how to obtain one record of the other of the. The blob column CSV file...

    You will be happy. This is a very unusual request, but you can try searching the interwebs - something can emerge.

    Basically what did your 'condition' is to take a simple piece of functionality, which is well understood and more easily satisfied using built-ins regular, and sought to implement pretty much the hardest way possible. So, good luck with that.

    Cheers, APC

    blog: http://radiofreetooting.blogspot.com

  • Error reading file using clob.

    I have to read a file line by line and put it in a plsql table.

    I have the following code

    FUNCTION to CREATE or REPLACE f_load_file_AB1 (p_dir IN VARCHAR2, p_filename IN VARCHAR2)

    RETURN VARCHAR2 IS

    Clob_tabtype. ARRAY TYPE IS CLOB

    INDEX OF DIRECTORY;

    Recseq_tabtype TYPE TABLE IS NUMBER

    INDEX OF DIRECTORY;

    clob_tab clob_tabtype;

    recseq_tab recseq_tabtype;

    l_bfile BFILE.

    l_clob CLOB.

    lang_ctx NUMBER: = DBMS_LOB.default_lang_ctx;

    attention NUMBER;

    DST_OFFSET NUMBER: = 1;

    offset NUMBER: = 1;

    l_charset NUMBER: = NLS_CHARSET_ID ('UTF8');

    l_line_clob CLOB: = EMPTY_CLOB;

    l_offset NUMBER: = 1;

    Line_Count NUMBER: = 0;

    line_loc NUMBER: = 0;

    PRAGMA AUTONOMOUS_TRANSACTION;

    BEGIN

    P_dir of IF p_filename don't IS NOT NULL AND IS NOT NULL THEN

    l_bfile: = BFILENAME (p_dir, p_filename);

    DBMS_LOB.CREATETEMPORARY (l_clob, CACHE = > FALSE);

    DBMS_LOB. OPEN (l_bfile, DBMS_LOB.lob_readonly);

    DBMS_LOB.loadclobfromfile (dest_lob = > l_clob,)

    src_bfile = > l_bfile,

    amount = > DBMS_LOB.getlength

    (l_bfile),

    dest_offset = > dst_offset.

    offset = > offset.

    bfile_csid = > l_charset,

    lang_context = > lang_ctx,

    WARNING = > warning);

    DBMS_LOB. CLOSE (l_bfile);

    -total number of lines in a file

    Line_Count: = REGEXP_COUNT (l_clob, chr (13): 10;)

    DBMS_LOB.CREATETEMPORARY (l_line_clob, CACHE = > FALSE);

    -extract line by line

    I'm in 1.line_count LOOP

    line_loc: = DBMS_LOB. INSTR (l_clob, chr (13) |) Chr (10), 1, i);

    line_loc: = line_loc - l_offset.

    l_line_clob: = DBMS_LOB.substr (l_clob, line_loc, l_offset);

    l_offset: = l_offset + line_loc;

    l_line_clob: = REPLACE (REPLACE (l_line_clob, CHR (10)), CHR (13));

    IF DBMS_LOB. GETLENGTH (l_line_clob) > 0 THEN

    clob_tab (i): = l_line_clob;

    recseq_tab (i): = i;

    END IF;

    END LOOP;

    -Extract the last line

    l_line_clob: = DBMS_LOB.substr (l_clob, dbms_lob.getlength (l_clob), l_offset);

    l_line_clob: = REPLACE (REPLACE (l_line_clob, CHR (10)), CHR (13));

    IF DBMS_LOB. GETLENGTH (l_line_clob) > 0 THEN

    (line_count + 1) clob_tab: = l_line_clob;

    (line_count + 1) recseq_tab: = + 1 line_count;

    END IF;

    DBMS_LOB.freeTemporary (l_line_clob);

    end if;

    return "thatsit;

    end f_load_file_AB1;

    I am facing problem to end while trying to free clob. Line DBMS_LOB.freetemporary (l_line_clob);

    If the size of my file is more than 32767 characters I get error

    ORA-06502: PL/SQL: digital error or value: specified incorrect LOB Locator: ORA-22275

    ORA-06512: at "SYS." DBMS_LOB", line 818

    ORA-06512: at "HR. F_LOAD_FILE_AB1', line 71-> that points to DBMS_LOB.freetemporary (l_line_clob); line of code.

    To resolve this issue, I added l_line_clob: = to_clob(' '); line just before DBMS_LOB.freetemporary (l_line_clob);

    Now, I get no error but I want to know the root cause of this problem and also a good solution.

    Thank you

    Ankita

    The problem is not with the length of l_clob itself, but the way that use you it in dbms_lob.substr for your last line

    DBMS_LOB.substr returns a null value if amount > 32767

    And a null clob cannot be released

    And also if you have a last blank line, i.e. two crlf at the end of l_clob freetemporary cannot too

    For example, it will work

    declare

    CLOB l_line_clob;

    Start

    l_line_clob: = dbms_lob.substr (' ', 1, 1);

    DBMS_LOB.freeTemporary (l_line_clob);

    end;

    And it will not

    declare

    CLOB l_line_clob;

    Start

    l_line_clob: = dbms_lob.substr (' ', 0, 1);

    DBMS_LOB.freeTemporary (l_line_clob);

    end;

    The best option is to check the clob before releasing it

    declare

    CLOB l_line_clob;

    Start

    l_line_clob: = dbms_lob.substr (' ', 0, 1);

    If l_line_clob is not null

    then

    DBMS_LOB.freeTemporary (l_line_clob);

    end if;

    end;

  • 'LOB not supported for type' error occurs when executing DBMS_LOB. FRAGMENT_INSERT

    Hi all
    I'm trying to launch DBMS_LOB. FRAGMENT_INSERT, but got error saying:
    ORA-43856: Unsupported LOB type for SECUREFILE LOB operation
    Suppose I have the following code:
    declare
    note_clob clob;
    note_clob2 clob;
    note_bfile bfile;
    buffer varchar2(10000);
    note_var varchar2(10000);
    warning int;
    dest_off int:=1;
    src_off int:=1;
    lang_ctx int:=0;
    amount int:=1500;
    
    begin
    --Create temp
    dbms_lob.createtemporary(note_clob,true);
    
    --Initialize BFILE
    note_bfile:=bfilename('TEMP_DIR','note.txt');
    --Open bfile
    dbms_lob.fileopen(note_bfile);
    
    dbms_lob.loadclobfromfile(note_clob,note_bfile,dbms_lob.lobmaxsize,dest_off,src_off,0,lang_ctx,warning);
    
    dbms_lob.fileclose(note_bfile);
    
    --Fragement Insert
    amount:=3;
    dest_off:=10;
    buffer:='end';
    dbms_lob.fragment_insert(note_clob,amount,dest_off,buffer); <==LINE 30
    
    --Read
    amount:=50;
    dbms_lob.read(note_clob,amount,1,note_var);
    
    dbms_output.put_line(note_var);
    end;
    /
    and I got:
    ERROR at line 1:
    ORA-43856: Unsupported LOB type for SECUREFILE LOB operation
    ORA-06512: at "SYS.DBMS_LOB", line 1076
    ORA-06512: at line 30
    What did I miss?

    Better subject.
    TA.

    only recently switched to 11g and 10g DBMS_LOB have FRAGMENT stuff

    http://download.Oracle.com/docs/CD/B28359_01/server.111/b28278/e43750.htm suggests

    ORA-43856: not taken object Type supported for operation SECUREFILE LOB
    Question: A SECUREFILE Lob operation was published on an unsupported object type.

    Action: Don't use this function for BASICFILE LOBs.

    Seems DBMS_LOB. FRAGMENT procedures work with LOB secure files only. :(

    Concerning

    Etbin

  • [g 11] can create xmltype holding 'forrest' with xmlagg(), but not with dbms_lob.append)

    (I'm testing the aggregation of xmltype items one by one) xmlagg() vs dbms_lob.append (b)).

    Well, this depends on the number of items of xmltype and their structure and size, which is more efficient.

    But what makes me mad, is that I am allowed to create some xmltype which is a 'forrest' (not a SINGLE root node, but a NUMBER OF knots of roots) using xmlagg().
    But when I do the aggregation via dbms_lob.append (), I can't create some xmltype of the result, because it contains a 'forrest '.

    So why is he allowed to go but not allowed the reverse?

    Kind regards

    Frank

    It's the way it works.  You wouldn't be able to save your forest in an XML document and treat it as XML valid because it is not.

    When you work with XML, you should always use XMLTYPE and XML functions, rather than manually stringing things together using DBMS_LOB.

  • DBMS_LOB. GETLENGTH in bytes

    I use Oralce 11.2.0.3. I'm using DBMS_LOB. GETLENGTH to determine the size of the CLOB. What's the value given by DBMS_LOB. GETLENGTH in bytes?

    by checking your charset of the data base.

    If you use the set of characters in a single byte (which means one byte for a tank) number of characters equals the number of bytes.

    If you use multi byte charset (which means two bytes for a tank), then probably the number of characters is equal to 2 * number of bytes.

    PS: to check your charset in the database:

    select * from nls_database_parameters where parameter = 'NLS_CHARACTERSET';
    

    Published by: Mustafa KALAYCI on 03.Tem.2012 08:53

  • DBMS_LOB within forms

    Hi, I use DBMS_LOB package to store large text data in the database. The problem is whenever I have deploy the form to another version of the database, I have to recompile the form. is it possible to construct a clob shaped object and save it to the database without using the DBMS_LOB package?
    Thank you

    It depends on your version of forms. Forms 6i R2 (6.0.8.11.3) and above have native support for BLOB, CLOB, and BFILE data types. When you create a datablock with the wizard block, forms will properly configure all columns that you have that use the BLOB, CLOB, and BFILE data type. This eliminates the need to use the DBMS_LOB package to read/write in the CLOB column.

    Hope this helps,
    Craig B-)

    If someone useful or appropriate, please mark accordingly.

  • difference btw utl_file and dbms_lob

    Hello

    What is the difference with utl_file, dbms_lob, doing the same file acess or difference?

    797525 wrote:

    What is the difference with utl_file, dbms_lob, doing the same file acess or difference?

    UTL_FILE is a PL/SQL package that provides a PL/SQL code with the operating system standard interface IO. You will find this same interface in languages like C, C++, Pascal, PHP, Perl, and others.

    DBMS_LOB is a PL/SQL package that allows you to manage an Oracle LOB data type. This data type is 'special' that it can contain objects of large data (such as video, sounds, images, documents, spreadsheets, etc.).

    Technically speaking, there is very little that is the same between the two.

    Conceptually, the two are however, interfaces 'files '. The only difference is that the files of UTL_FILE , external access (on the file system of the operating system). Whereas the DBMS_LOB provides the ability to create and store and manage "files" directly in the database. (there are also a BFILE data type that resembles a LOB, but is actually an external file)

    It's rarely a good idea to get out of the database in a file system of an operating system with UTL_FILE. There are problems of security and access control. Concurrency issues and transactions. Problems with the integrity of the data. Problems with the backup of the data. Etc.

    So, in general, when you're dealing with the concept of "+ files +" in Oracle, you should look at first using the Oracle database itself - and deal with files like LOBs using DBMS_LOB.

Maybe you are looking for

  • ImTranslator-translator

    I downloaded ImTranslator-translator for Firefox, it appears in my list ad - the, I activated the option to display the icon in my toolbar in the menu 'options', but it does not appear on the toolbar, or on the supplementary list in the menu on the s

  • How is it, I don't see any of my themes of appearance, even when they are turned on?

    I don't see one of my themes of appearance, even when they are activated. I tried deactivating and reactivating them and gone through all my themes, but none show except the default 20.0.01; which when I try other themes shows even when it is disable

  • I can't install Fedora core Linux on Satellite U400

    Dear friends, I have a laptop Toshiba Satellite U400.As you know today all laptops that is coming from Windows Vista.So, regarding my project, I tried to install Windows XP and Linux on my laptop but unfortunately I could not install at the beginning

  • Radio On / Off

    Helloso I found that since the API Version 4.x, it is possible to toggle the unit radio. This is how I do it: int i = RadioInfo.getActiveWAFs();int iState = RadioInfo.getState();if (iState==0){//onRadio.activateWAFs(i);Dialog.alert("Radio switched on

  • All my Stock of Adobe. I downloaded the files I are blobs of photo why are they VECTOR?

    OK, so I signed up for ADOBE STOCK and I've downloaded several. The files HAVE Adobe Illustrator, but in reality they are just photo blobs when I DOWNLOAD AND SAVE ON COMPUTER. When I put in a library are always blobs, they also have watermarks. I'm