Dbms_lob Vs Instr

Hi,
To read the clob by line by line dbms_lob.read is better or using instr function is better?
experts please suggest.
Thanks & Regards,
Ramana.

Hi Justin,
Great to see your immediate reply. First let me correct myself. I'm reading the line by line using regular_expr later I'm reading the string by using dbms_lob.read method. It was little slow. Then, I've applied the same logic using instr function. But I didn't see much difference. i thought i want know which is the best way.
Come to external table. After loading i want do next process. But there is no way that i know that external table is loaded. so that is why I'm loading the clob into a table and from there I'm reading and populating another table.
Correct me If I'm wrong conceptually in terms of external tables.
Regards,
Ramana.

Similar Messages

  • Dbms_lob.instr question

    Hello,
    I have a field that holds CLOBs in the database. I have a textfield in which the user can enter a target string, then I hope to use dbms_lob.instr to search for the target string in CLOB. The code looks like: dbms_lob.instr(upper(I.COMMENTS),upper(nvl(:P26_SEARCH_NAME,I.COMMENTS))). If I replace the textfield value :P26_SEARCH_NAME with a string, the line works fine, but the current line returns the error
    ORA-22835: Buffer too small for CLOB to CHAR or BLOB to RAW conversion (actual: 6250, maximum: 4000) Can someone offer some help with a fix?

    Steven - Try v('P26_SEARCH_NAME') as a test to see if it makes any difference. If not, I can look at your test case if you put it on apex.oracle.com.
    Scott

  • DBMS_LOB.instr (looking backwards for a string)

    I am trying to find the position of the first instance of a string ('><'), but staring at a position in the CLOB (not the start) and working backwards
    I thought this may work:
    num := DBMS_LOB.instr(L_CLOB, '><', 5000, -1);
    But unfortunately it returns nothing....
    Anyone able to help me?
    Thanks,

    I think you've got the parameters scrambled. Try this:
       num := DBMS_LOB.instr(L_CLOB, '><', -1, 1);Cheers, APC

  • DBMS_LOB.INSTR - Searching for a pattern

    Hi
    I have a program supporting several databases. F.ex SQL2000 and Oracle 8/9.
    The field in question, text, might contain a lot of characters. In Oracle, it's a CLOB,
    on SQL2000 it's a varchar. It is not possible for me to alter the database-structure in
    any ways at this moment. The database-schema is locked.
    My question is pretty simple, you have probably seen it before.
    In SQL2000 I can use this query:
    select count(*) from crm5.text where text like 'n%'.
    The result returned = 8.
    The same on Oracle will be somewhat like:
    select count(*) from crm5.text where dbms_lob.instr( text, 'n') > 0
    The result returned = 29.
    The databases has the same data.
    It seems to me that the dbms_lob.instr
    does a (case-sensitive) query like this:
    select count(*) from crm5.text where text like '%n%
    Is this the right assumption? How can I get the correct number
    of rows and do the search case-insensitive at the same time not
    killing the performance of the database? We use a pretty smart
    little thing on "normal" LIKE. But how can we do this with the
    CLOB?
    Regards,
    Ivar

    Found the solution.
    On Oracle 9, use LIKE as you want.
    On Oracle 8, use
    select count(*) from crm5.text
    where dbms_lob.instr( text, 'N') = 1
    or dbms_lob.instr( text, 'n') = 1.
    Ivar (same account, different mail-address).

  • Can dbms_lob.instr have end position?

    I am extracting data from xml using dbms_lob utility and the pattern in XML is as below.
    <Atag>
    <Btag>
    <Ctag>value</Ctag>
    </Btag>
    <Btag>
    <Ctag>value</Ctag>
    <Dtag>value</Dtag>
    </Btag>
    <Btag>
    <Ctag>value</Ctag>
    <Dtag>value</Dtag>
    </Btag>
    </Atag>
    I want to extract all tag values inside <Btag> which will be nohting but Ctag and Dtag values. There can be any occurence of <Btag> in this xml. When I use like this,
    val:=0;
    <LOOP>
    val1:=dbms_lob.instr(xml,'<Btag>',val);
    val2:=dbms_lob.instr(xml,'</Btag>,val1);
    val3:=case(val1) when 0 then 0 else dbms_lob.instr(xml,'<Ctag>,val1) end;
    val4:=case(val3) when 0 then 0 else dbms_lob.instr(xml,'</Ctag>,val3) end;
    val5:=case(val1) when 0 then 0 else dbms_lob.instr(xml,'<Dtag>,val1) end;
    val6:=case(val5) when 0 then 0 else dbms_lob.instr(xml,'</Dtag>,val5) end;
    In this case as <Dtag> doesnt exist inside the first occurence of <Btag>, so it gets the value from the next one which is not what I require. I want that to be set to null/zero so for which I want to search only between the first occurence of <Btag> and </Btag>.
    I know it is confusing but can some one of you tell me how to go and find the values of <Ctag> and <Dtag> between each occurence of <Btag>. If they are not present I want the value to be set to zero/null.
    Thanks in advance.

    test@ora>
    test@ora> @ver1
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
    1 row selected.
    test@ora>
    test@ora>
    test@ora> --
    test@ora> with t as (
      2    select '<Atag>
      3  <Btag>
      4  <Ctag>Tootsie</Ctag>
      5  </Btag>
      6  <Btag>
      7  <Ctag>Psycho</Ctag>
      8  <Dtag>Casablanca</Dtag>
      9  </Btag>
    10  <Btag>
    11  <Ctag>Goodfellas</Ctag>
    12  <Dtag>Chinatown</Dtag>
    13  </Btag>
    14  </Atag>' as x from dual)
    15  --
    16  select
    17    x,
    18    regexp_replace(modx,'(.*?)<Btag>(.*?)</Btag>.*$','\2',1,1) as txt1,
    19    regexp_replace(modx,'(.*?)(<Btag>(.*?)</Btag>){1}<Btag>(.*?)</Btag>.*$','\4',1,1) as txt2,
    20    regexp_replace(modx,'(.*?)(<Btag>(.*?)</Btag>){2}<Btag>(.*?)</Btag>.*$','\4',1,1) as txt3
    21  from (
    22    select regexp_replace(x,'(>).(<)','\1\2',1,0,'n') as modx, x from t
    23  );
    X                              TXT1                 TXT2                                        TXT3
    <Atag>                         <Ctag>Tootsie</Ctag> <Ctag>Psycho</Ctag><Dtag>Casablanca</Dtag>  <Ctag>Goodfellas</Ctag><Dtag>Chinatown</Dtag>
    <Btag>
    <Ctag>Tootsie</Ctag>
    </Btag>
    <Btag>
    <Ctag>Psycho</Ctag>
    <Dtag>Casablanca</Dtag>
    </Btag>
    <Btag>
    <Ctag>Goodfellas</Ctag>
    <Dtag>Chinatown</Dtag>
    </Btag>
    </Atag>
    1 row selected.
    test@ora>
    test@ora>
    test@ora>@Keith - Regular expressions are from 10g upwards.
    isotope

  • Dbms_lob.instr searching backwards

    How can I use dbms_lob.instr to locate a string backward? such as "locate the position of the first 'xxx' before the current position (current pos == 88)?
    Thanks,
    Kevin

    SQL> set serveroutput on size 100000;
    SQL> DECLARE
      2    str   VARCHAR2(100) := 'aiiisalalkjsiiiksjjjslakjsljliiiljflakjfljsldiiiiiisfsljslkjdoooofdiiiiiisfsljslkjdoooof';
      3    pos   NUMBER;
      4    occur NUMBER := 1;
      5    subst VARCHAR2(3) := 'iii';
      6  BEGIN
      7    WHILE instr(str,
      8                subst,
      9                1,
    10                occur) > 0
    11    LOOP
    12      pos   := instr(str,
    13                     'iii',
    14                     1,
    15                     occur);
    16      occur := occur + 1;
    17    END LOOP;
    18    dbms_output.put_line('last occurrence of ' || subst ||
    19                         ' begins at position ' || pos);
    20  END;
    21  /
    last occurrence of iii begins at position 71
    PL/SQL procedure successfully completed
    Peter

  • Error in using DBMS_LOB Package

    Hi,
    I am attaching a PDF File through a database procedure as shown below
    create or replace procedure load_document(document_id in number, filename IN varchar2, doc_desc IN VARCHAR2, doc_type IN VARCHAR2) as
    f_lob bfile;
    b_lob blob;
    --document_name varchar2(30);
    --mime_type varchar2(30);
    document_name oea_documents.document_name%TYPE;
    mime_type oea_documents.document_mime_type%TYPE;
    dot_pos number;
    v_file_type VARCHAR2(10);
    begin
    -- Find the position of the dot ('.') located in the filename
    dot_pos := instr(filename,'.');
    -- Get the filename without extension and use it as image name
    document_name := substr(filename,1,dot_pos-1);
    -- Build the mime type . Retrieve the file extension and add it to 'image/'
    v_file_type := SUBSTR( filename, dot_pos+1, Length(Filename) );
    IF ( UPPER(v_file_type) IN ('JPG','JPEG','TIF','TIFF','GIF') ) THEN
    mime_type := 'image/'||substr( filename , dot_pos+1 , length(filename) );
    ELSIF ( UPPER(v_file_type) = 'PDF' ) THEN
    mime_type := 'application/pdf';
    ELSIF ( UPPER(v_file_type) = 'DOC' )THEN
    mime_type := 'application/msword';
    ELSIF ( UPPER( v_file_type) = 'XLS') THEN
    mime_type := 'application/ms-excel';
    ELSE
    mime_type := 'image/'||substr( filename , dot_pos+1 , length(filename) );
    END IF;
    insert into oea_documents (document_id,
    document_name,
    document_mime_type,
    document,
    document_description,
    document_type
    values(document_id, document_name, mime_type, empty_blob(),doc_desc,doc_type) return document into b_lob;
    -- /!\ Directory name has to be UpperCase !
    f_lob := bfilename('FILE_LOAD',filename);
    o_dset_test('5');
    dbms_lob.fileopen(f_lob,dbms_lob.file_readonly);
    o_dset_test('6');
    dbms_lob.loadfromfile(b_lob,f_lob,dbms_lob.getlength(f_lob) );
    dbms_lob.fileclose(f_lob);
    commit;
    end;
    FILE_LOAD is a folder on the database server(unix).
    I have also tried to give the full path on the unix databse server instead of FILE_LOAD directory but then it gives error ora-22285.
    while executing this procedure I am getting the error ora-22288(Invalid file or directory).
    But this occurs randomly
    For instance i tried to attach a pdf file with the name cross.pdf ,it gave me the above error and when i renamed the file as Cross.pdf it attached successfully.
    The error comes whilke executing the statement dbms_lob.fileopen(f_lob,dbms_lob.file_readonly);
    Please guide on the above issue.

    Hi,
    Welcome to the forum!
    user1356624 wrote:
    f_lob := bfilename('FILE_LOAD',filename);
    FILE_LOAD is a folder on the database server(unix).
    I have also tried to give the full path on the unix databse server instead of FILE_LOAD directory but then it gives error ora-22285.The first argument to BFILENAME is the name of a directory object, as found in the directory_name column of all_directories. That is not the same thing as a folder name, which is found in the directory_path column of all_directories. Look up [CREATE DIRECTORY|http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/statements_5007.htm#sthref6211] in the SQL Language manual for a description of Oracle's directory objects.
    If you have problems with this, post the results of
    SELECT  *
    FROM    all_directories;It might also be useful to see the Oracle "CREATE DIRECTORY" command that was used.
    As you probably noticed, this site compresses white space by default.
    When you post code or results on this site, type these 6 characters:
    (small letters only, inside curly brackets) before and after sections of formatted text, to preserve spacing.
    Edited by: Frank Kulash on Aug 10, 2009 3:35 PM
    Added link.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • PDF file created from Oracle Report is created wrongly using dbms_lob

    Hi,
    Please help. It is very urgent.
    I am using Oracle Developer 10gR2, Oracle Report 10.1.2 on Windows 2000.
    I would like to attach the PDF file created by Oracle Report to the Notification sent from Workflow.
    I use the following package procedure in my Workflow.
    procedure Create_File_Attachment (document_id   in varchar2, display_type  in varchar2,
                                                                                         document      in out blob, document_type in out varchar2)
    is
         l_itemtype          varchar2(100);
         l_itemkey           varchar2(100);
         l_output_directory  varchar2(30);
         l_filename          varchar2(255);
         src_loc             bfile;
         bdoc                blob;
         src_offset          number := 1;
         dst_offset          number := 1;
         amount              number;
    begin
         l_itemtype := substr(document_id, 1, instr(document_id, ':') - 1);
         l_itemkey := substr(document_id, instr(document_id, ':') + 1, length(document_id) - 2);
         l_output_directory := 'USR_TMP_DIR';
         l_filename := Wf_Engine.GetItemAttrText(l_itemtype, l_itemkey, 'ATR_FILENAME');
         src_loc := bfilename(l_output_directory,l_filename);
         dbms_lob.createTemporary(bdoc, FALSE, dbms_lob.call);
         dbms_lob.fileopen(src_loc, dbms_lob.file_readonly);
         dbms_lob.loadblobfromfile(bdoc,src_loc,dbms_lob.lobmaxsize,src_offset,dst_offset);
         dbms_lob.fileclose(src_loc);
         amount := dbms_lob.getLength(bdoc);
         dbms_lob.copy(document,bdoc,amount,1,1);
         document_type := 'application/pdf; name=attach.pdf';
    end Create_File_Attachment;Oracle Report created the PDF file correctly (original.pdf).
    I tried to attach the PDF into my Workflow.
    I can see the file is attached (attach.pdf), but it cannot be opened.
    The Adobe shows : 'A drawing error occured.' each time I open the attachment.
    I compare the original.pdf and the attach.pdf
    However, there is one specific difference
    - in original.pdf, the line started with '.' (single period)
    in attach.pdf, the line is started with '..' (two periods)
    Thus the attachment cannot be opened.
    After I delete the period, it can be opened.
    Question:
    - Has someone ever succeed in attaching the PDF created from Report?
    - Are the codes above is wrong?
    - Or perhaps the DBMS_LOB.LOADBLOBFROMFILE always double the single period on front of the line?
    - Is there any solution on this?
    Note:
    I have succeed in attaching PDF files unless the PDF created by the Report.
    Sorry for the long post.
    Please help. It is very urgent.
    Any help is appreciated.
    Many thanks,
    Buntoro

    Hi,
    Please help. It is very urgent.
    I am using Oracle Developer 10gR2, Oracle Report 10.1.2 on Windows 2000.
    I would like to attach the PDF file created by Oracle Report to the Notification sent from Workflow.
    I use the following package procedure in my Workflow.
    procedure Create_File_Attachment (document_id   in varchar2, display_type  in varchar2,
                                                                                         document      in out blob, document_type in out varchar2)
    is
         l_itemtype          varchar2(100);
         l_itemkey           varchar2(100);
         l_output_directory  varchar2(30);
         l_filename          varchar2(255);
         src_loc             bfile;
         bdoc                blob;
         src_offset          number := 1;
         dst_offset          number := 1;
         amount              number;
    begin
         l_itemtype := substr(document_id, 1, instr(document_id, ':') - 1);
         l_itemkey := substr(document_id, instr(document_id, ':') + 1, length(document_id) - 2);
         l_output_directory := 'USR_TMP_DIR';
         l_filename := Wf_Engine.GetItemAttrText(l_itemtype, l_itemkey, 'ATR_FILENAME');
         src_loc := bfilename(l_output_directory,l_filename);
         dbms_lob.createTemporary(bdoc, FALSE, dbms_lob.call);
         dbms_lob.fileopen(src_loc, dbms_lob.file_readonly);
         dbms_lob.loadblobfromfile(bdoc,src_loc,dbms_lob.lobmaxsize,src_offset,dst_offset);
         dbms_lob.fileclose(src_loc);
         amount := dbms_lob.getLength(bdoc);
         dbms_lob.copy(document,bdoc,amount,1,1);
         document_type := 'application/pdf; name=attach.pdf';
    end Create_File_Attachment;Oracle Report created the PDF file correctly (original.pdf).
    I tried to attach the PDF into my Workflow.
    I can see the file is attached (attach.pdf), but it cannot be opened.
    The Adobe shows : 'A drawing error occured.' each time I open the attachment.
    I compare the original.pdf and the attach.pdf
    However, there is one specific difference
    - in original.pdf, the line started with '.' (single period)
    in attach.pdf, the line is started with '..' (two periods)
    Thus the attachment cannot be opened.
    After I delete the period, it can be opened.
    Question:
    - Has someone ever succeed in attaching the PDF created from Report?
    - Are the codes above is wrong?
    - Or perhaps the DBMS_LOB.LOADBLOBFROMFILE always double the single period on front of the line?
    - Is there any solution on this?
    Note:
    I have succeed in attaching PDF files unless the PDF created by the Report.
    Sorry for the long post.
    Please help. It is very urgent.
    Any help is appreciated.
    Many thanks,
    Buntoro

  • Using dbms_lob in trigger 10gR2

    Hello,
    I'm trying to read from a clob using dbms_lob in my trigger and assigning the value to a variable. My trigger is compiling fine, but it doesn't seem to be working.
    I'm using 10gR2. Am I misunderstanding how to read from/assign to a variable in a trigger?
    Line from trigger code:
    v_serial_start := dbms_lob.instr(:new.search_xml_clob,'serial=') + 8;
    Thanks,
    Mimi

    Here's a quick example that works fine for me....
    ME_XE?create table clobberin_tyme
      2  (
      3     some_column    number,
      4     variable_value number default 0,
      5     some_clob      clob default empty_clob()
      6  );
    Table created.
    Elapsed: 00:00:03.98
    ME_XE?
    ME_XE?
    ME_XE?create or replace trigger clobberin_tymeT01
      2  before insert or update on clobberin_tyme
      3  for each row
      4  declare
      5     v_serial_start    number;
      6  begin
      7
      8     v_serial_start       := dbms_lob.instr(:new.some_clob,'serial=') + 8;
      9
    10     :new.variable_value  := v_serial_start;
    11
    12  end;
    13  /
    Trigger created.
    Elapsed: 00:00:02.62
    ME_XE?
    ME_XE?
    ME_XE?insert into clobberin_tyme (some_column) values (1);
    1 row created.
    Elapsed: 00:00:00.31
    ME_XE?
    ME_XE?select * from clobberin_tyme;
           SOME_COLUMN     VARIABLE_VALUE SOME_CLOB
                     1                  8
    1 row selected.
    Elapsed: 00:00:00.17
    ME_XE?
    ME_XE?update clobberin_tyme
      2     set   some_column = 2,
      3           some_clob = 'hello world serial= coco puffs, i am cucu for them';
    1 row updated.
    Elapsed: 00:00:00.25
    ME_XE?
    ME_XE?select * from clobberin_tyme;
           SOME_COLUMN     VARIABLE_VALUE SOME_CLOB
                     2                 21 hello world serial= coco puffs, i am cucu for them
    1 row selected.
    Elapsed: 00:00:00.01

  • Dbms_lob wwv_flow_files

    I created a file upload as shown in the how-to, which I am using to upload csv files to the wwv_flow_files table. I would like to take the blob and break it apart for insert to a processing table. However, I am new to dbms_lob and would like any help possible. Are there any good references to using this in a pl/sql package to create inserts from blob fields?
    Many Thanks!!!

    Ok, I was able to find a solution and I'll post what I have. I was uploading a csv file with 3 fields (number, text, text) to the flow_files table. I was able to break this apart for insert using the anonymous block below. I'll probably store this as a function so that I can return a success/failure message.
    I hope this can help someone else!
    Begin
    Declare
    v_blob blob;                    
    v_raw raw(32767);     
    v_len number;
    v_pos integer := 1;
    v_amt binary_integer := 15;
    v_out varchar2(500);
    v_sql varchar2(255);
    v_search raw(4);
    l_linebreak varchar2(2) := chr(13)||chr(10);
    v_pad1 varchar2(5);
    v_pad2 varchar2(7);
    v_pad3 varchar2(5);
    begin
    v_sql := 'insert into table_x (field1,field2,field3) values ';
    v_search := utl_raw.cast_to_raw(l_linebreak);
    select BLOB_CONTENT
    into v_blob
    from WWV_FLOW_FILE_OBJECTS$
    where id = 775113501593078;
    v_pad1 := ','||'''';
    v_pad2 := ''''||','||'''';
    v_pad3 := ''''||')';
    v_pos := 1;
    loop
    v_amt := DBMS_LOB.INSTR(v_blob,v_search,v_pos);
    v_amt := v_amt - v_pos;
    If v_amt &lt; 1 then
    v_amt := 1;
    End if;
    /* Read current sector from blob into raw*/
    DBMS_LOB.READ(v_blob,v_amt,v_pos,v_raw);
    v_out := utl_raw.cast_to_varchar2(v_raw); --convert raw to varchar2 and set to output variable
    --dbms_output.put_line(v_out);
    v_out := replace(v_out,chr(10),'');
    v_out := replace(v_out,chr(13),'');
    If length(v_out) &gt; 0 then
    v_out := v_sql||'('||replace(substr(v_out,1,instr(v_out,',')),',',v_pad1)
    ||replace(substr(v_out,instr(v_out,',')+1,(length(v_out)-(instr(v_out,',')))),',',v_pad2)
                   ||v_pad3;
    --dbms_output.put_line(v_out);
         Execute immediate v_out;
    End if;
    v_out := null;
    v_raw := null;
    v_pos := v_pos + v_amt +1;
    v_amt := null;
    end loop;
    EXCEPTION
    WHEN others THEN
         dbms_output.put_line(sqlerrm);
    NULL;
    end;
    end;

  • DBMS_LOB IN ORACLE 8i TRIGGER

    Hello friends;
    I'm working with oracle 8i
    This is my TABLE
    CREATE TABLE PROBCLOB
    ( CAMPO1 CLOB,
    CAMPO2 NUMBER(1) );
    This is my TRIGGER
    CREATE OR REPLACE TRIGGER PROBANDO BEFORE INSERT ON PROBCLOB FOR EACH ROW
    DECLARE
    cCAMPO CLOB;
    nNUM NUMBER( 10 );
    BEGIN
    SELECT :NEW.CAMPO1 INTO cCAMPO FROM DUAL;
    SELECT DBMS_LOB.INSTR( cCAMPO, 'http' ) INTO nNUM FROM DUAL;
    IF nNUM <> 0 THEN
    :NEW.CAMPO2 := 0;
    END IF;
    END;
    When I try to insert in this table ( example: INSERT INTO PROBCLOB VALUES ( 'this is my web http:\\www.oracle.com', 1 ); )
    Then I have an error:
    ORA-22275: invalid LOB locator specified
    ¿Can I find the text "http" in my CLOB in a TRIGGER for change the value of CAMPO2?
    Thank you

    In oracle 10 this is OK

  • Dbms_lob-replace

    I have a clob database field and I want to replace every occurence of a char with another one(for ex. all 'a's to 'b's). There is not a repalce function in dbms_lob package and I want to know if there is a practical way of doing this.
    Thanks a lot.

    It's not ideal but as you're looking for chunks of text this is probably the only way.
    (1) Create a temporary LOB.
    (2) Use DBMS_LOB.INSTR() to find "dangeous HTML", however you define that.
    (3) Use DBMS_LOB.SUBSTR() and DBMS_LOB.WRITEAPPEND() to copy the safe HTML to the temporary lob.
    (4) Overwrite the CLOB with the temporary LOB.
    There may be smarter ways of doing this in 10g with regular expressions, but without knowing more about your scenario I wouldn't like to comment further.
    Cheers, APC

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

  • File content retrive/view problem using DBMS_LOB...?

    Below this procedure working fine but getting buffer length/file content display problem...
    CREATE OR REPLACE Procedure READ_FILE_LOB_tmp IS
    l_dir CONSTANT VARCHAR2(30) := 'READ_LOB_DIR';
    l_fil CONSTANT VARCHAR2(30) := 'testfile.txt';
    l_sen CONSTANT RAW(100) := UTL_RAW.CAST_TO_RAW(CHR(10));
    l_loc BFILE;
    l_pos NUMBER := 1;
    l_sum BINARY_INTEGER := 0;
    l_buf VARCHAR2(400);
    l_end NUMBER;
    l_getlength NUMBER;
    l_ret BOOLEAN := FALSE;
    BEGIN
    l_loc := BFILENAME(l_dir, l_fil);
    l_getlength := DBMS_LOB.getlength(l_loc);
    l_ret := DBMS_LOB.FILEEXISTS(l_loc) = 1;
    IF (l_ret) THEN
    DBMS_LOB.OPEN(l_loc, DBMS_LOB.LOB_READONLY);
    LOOP
    l_end := DBMS_LOB.INSTR(l_loc, l_sen, l_pos, 1);
    IF l_end >= l_getlength THEN
    EXIT;
    END IF;
    l_sum := l_end - l_pos;
    DBMS_LOB.READ(l_loc, l_sum, l_pos, l_buf);
    dbms_output.put_line(UTL_RAW.CAST_TO_VARCHAR2(l_buf));
    l_pos := l_pos + l_sum + 1;
    END LOOP;
    DBMS_LOB.CLOSE(l_loc);
    END IF;
    END;
    My file content:
    Test Content1
    Test Content2
    Test Content3
    Test Content4
    Test Content5
    When i run this procedure, get the output like below format:
    Test Content1
    Test Content2
    Test Content3
    Test Content4
    Test Content5
    But I want to display as per file content format...

    I changed the code like...
    CREATE OR REPLACE Procedure READ_FILE_LOB IS
    l_dir CONSTANT VARCHAR2(30) := 'READ_LOB_DIR';
    l_fil CONSTANT VARCHAR2(30) := 'testfile.txt';
    l_seb CONSTANT RAW(100) := UTL_RAW.CAST_TO_RAW(CHR(32));
    l_sen CONSTANT RAW(100) := UTL_RAW.CAST_TO_RAW(CHR(10));
    l_loc BFILE;
    l_pos NUMBER := 1;
    l_sum BINARY_INTEGER := 0;
    l_buf VARCHAR2(4000);
    l_end NUMBER;
    l_ret BOOLEAN := FALSE;
    l_getlength NUMBER;
    BEGIN
    l_loc := BFILENAME(l_dir, l_fil);
    l_getlength := DBMS_LOB.getlength(l_loc);
    --dbms_output.put_line(l_getlength);
    If l_getlength > 0 then
    l_ret := DBMS_LOB.FILEEXISTS(l_loc) = 1;
    IF (l_ret) THEN
    DBMS_LOB.OPEN(l_loc, DBMS_LOB.LOB_READONLY);
    LOOP
    l_end := DBMS_LOB.INSTR(l_loc, l_sen, l_pos, 1);
    IF l_end = 0 THEN
    l_sum := l_getlength - l_pos + 1;
    DBMS_LOB.READ(l_loc, l_sum, l_pos, l_buf);
    dbms_output.put_line(UTL_RAW.CAST_TO_VARCHAR2(l_buf));
    EXIT;
    END IF;
    l_sum := l_end - l_pos;
    DBMS_LOB.READ(l_loc, l_sum, l_pos, l_buf);
    DBMS_LOB.TRIM(l_buf, (l_sum * 2) - 2);
    dbms_output.put_line(UTL_RAW.CAST_TO_VARCHAR2(l_buf));
    l_pos := l_pos + l_sum + 1;
    END LOOP;
    DBMS_LOB.CLOSE(l_loc);
    END IF;
    END IF;
    EXCEPTION
    WHEN OTHERS THEN
    dbms_output.put_line('Error:' || SQLERRM);
    DBMS_LOB.CLOSE(l_loc);
    END;
    Now its working fine with my format

  • Substr and instr for long column

    Plesae need support ,how can use instr and substr function for column with long datatype
    select substr(rec,1,(instr(rec,'?',1))) from F_DE_O_HISTORY_QUEUE_PRE_TST2
    rec column is long,When execute this select message displayed as ORA-00932: inconsistent datatypes: expected NUMBER got LONG

    Try to create a global temporary table and work on this table using DBMS_LOB.INSTR and DBMS_LOB.SUBSTR:
    SQL> desc t;
    Name                                      Null?    Type
    X                                                  NUMBER(38)
    Y                                                  LONG
    SQL> create global temporary table tmp on commit preserve rows as select x, to_lob(y) as y from t ;
    Table created.
    SQL> desc tmp;
    Name                                      Null?    Type
    X                                                  NUMBER(38)
    Y                                                  CLOBEdited by: P. Forstmann on 19 janv. 2010 12:42

Maybe you are looking for