Search for a particular string in Oracle clob column

前端 未结 5 1157
长情又很酷
长情又很酷 2020-12-14 16:18

How to get a particular string from a clob column?

I have data as below which is stored in clob column called product_details

CALCULATIO         


        
相关标签:
5条回答
  • 2020-12-14 16:56
    select *  
    from TABLE_NAME
    where dbms_lob.instr(COLUMNNAME,'searchtext') > 0;
    
    0 讨论(0)
  • 2020-12-14 16:58

    Below code can be used to search a particular string in Oracle clob column

    select *  
    from RLOS_BINARY_BP
    where dbms_lob.instr(DED_ENQ_XML,'2003960067') > 0;
    

    where RLOS_BINARY_BP is table name and DED_ENQ_XML is column name (with datatype as CLOB) of Oracle database.

    0 讨论(0)
  • 2020-12-14 17:00

    You can just CAST your CLOB value into a VARCHAR value and make your querie like a

    0 讨论(0)
  • 2020-12-14 17:04

    ok, you may use substr in correlation to instr to find the starting position of your string

    select 
      dbms_lob.substr(
           product_details, 
           length('NEW.PRODUCT_NO'), --amount
           dbms_lob.instr(product_details,'NEW.PRODUCT_NO') --offset
           ) 
    from my_table
    where dbms_lob.instr(product_details,'NEW.PRODUCT_NO')>=1;
    
    0 讨论(0)
  • 2020-12-14 17:07

    Use dbms_lob.instr and dbms_lob.substr, just like regular InStr and SubstStr functions.
    Look at simple example:

    SQL> create table t_clob(
      2    id number,
      3    cl clob
      4  );
    
    Tabela zosta│a utworzona.
    
    SQL> insert into t_clob values ( 1, ' xxxx abcd xyz qwerty 354657 [] ' );
    
    1 wiersz zosta│ utworzony.
    
    SQL> declare
      2    i number;
      3  begin
      4    for i in 1..400 loop
      5        update t_clob set cl = cl || ' xxxx abcd xyz qwerty 354657 [] ';
      6    end loop;
      7    update t_clob set cl = cl || ' CALCULATION=[N]NEW.PRODUCT_NO=[T9856] OLD.PRODUCT_NO=[T9852].... -- with other text ';
      8    for i in 1..400 loop
      9        update t_clob set cl = cl || ' xxxx abcd xyz qwerty 354657 [] ';
     10    end loop;
     11  end;
     12  /
    
    Procedura PL/SQL zosta│a zako˝czona pomyťlnie.
    
    SQL> commit;
    
    Zatwierdzanie zosta│o uko˝czone.
    SQL> select length( cl ) from t_clob;
    
    LENGTH(CL)
    ----------
         25717
    
    SQL> select dbms_lob.instr( cl, 'NEW.PRODUCT_NO=[' ) from t_clob;
    
    DBMS_LOB.INSTR(CL,'NEW.PRODUCT_NO=[')
    -------------------------------------
                                    12849
    
    SQL> select dbms_lob.substr( cl, 5,dbms_lob.instr( cl, 'NEW.PRODUCT_NO=[' ) + length( 'NEW.PRODUCT_NO=[') ) new_product
      2  from t_clob;
    
    NEW_PRODUCT
    --------------------------------------------------------------------------------
    T9856
    
    0 讨论(0)
提交回复
热议问题