Oracle PL/SQL - String operations on CLOBs


You can use regular string operations on CLOBs:

  • search for the patterns,
  • get length,
  • get part of the code,
  • and so on

The following code implements a search or indexing routine for all large text files loaded in the database.

     v_manual_cl   CLOB;
     v_nr          NUMBER;
     v_tx          VARCHAR2 (2000);
     v_add_tx      VARCHAR2 (2000):='Loaded: '||TO_CHAR(SYSDATE,'mm/dd/yyyy hh24:mi');
     select manual_cl             
        into v_manual_cl
        from t_product
     where id = 1
     for update;      
     DBMS_LOB.writeappend (v_manual_cl,LENGTH (v_add_tx), v_add_tx);                                
     v_nr := INSTR (v_manual_cl, 'Loaded:', -1);                       
     v_tx := SUBSTR (v_manual_cl, v_nr);
     DBMS_OUTPUT.put_line (v_tx);

Related Topic