title: How can I loop and output original value
body: <p>I am printing values to the output but I am not sure how to grab the original value before it was updated and display it.</p>
  
  <pre><code>declare
      v_ids varchar2(4000); 
  
     begin
  
     update time_line tl
     set tl.limit_template = 'LIM0178'
      where tl.limit_template IN
         (select tl.limit_template
            from base_timeline_section bbts,
                 base_timeline_org     bts,
                 trmt_timeline         tl
           where bbts.base_trmt_set_id = bts.base_trmt_set_id
             and tl.limit_id = bts.limit_id
             and bbts.bse_trmt_st_tplt_id = '720')
         returning listagg(tl.limit_template, ',') within group 
                       (order by tl.limit_template) into v_ids;
       dbms_output.put_line('Updated IDs: ' || v_ids || ' to LIM0178');
       end;
  </code></pre>
  
  <p>Right now I get the following output: Updated IDs: </p>
  
  <p>LIM0178 to LIM0178</p>
  
  <p>What i want is</p>
  
  <p>original value: 6165 changed to new value: LIM0178</p>
  
  <hr>
  
  <pre><code> declare
      v_ids varchar2(4000); 
      v_ids2 varchar2(4000);
     begin
      select listagg(tl.limit_template, ',') within group (order by 
      tl.limit_template) into v_ids
        from base_timeline_section bbts,
             base_timeline_org     bts,
             trmt_timeline         tl
       where bbts.base_trmt_set_id = bts.base_trmt_set_id
         and tl.limit_id = bts.limit_id
         and bbts.bse_trmt_st_tplt_id = '720';
  
  update time_line tl
     set tl.limit_template = 'LIM0178'
   where tl.limit_template IN (select REGEXP_SUBSTR (v_ids, '[^,]+', 1, level) 
                                 from (select rownum from dual ) 
                              connect by level &lt;= length(regexp_replace(v_ids,'[^,]*'))+1);
  
  
   dbms_output.put_line('Updated IDs: ' || v_ids || ' to LIM0178');
  
  
    select listagg(iplu.limit_template_id, ',') within group (order by iplu.limit_template_id)into v_ids2
    from base_timeline_section bbts,
         base_timeline_org     bts,
         trmt_timeline         tl,
         timeline_update_limit iplu
     where bbts.base_trmt_set_id = bts.base_trmt_set_id
     and tl.limit_id = bts.limit_id
     and bbts.bse_trmt_st_tplt_id = '720'
     and iplu.limit_template_id = tl.limit_template;
  
  
  update timeline_update_limit iplu
     set iplu.limit_template_id = 'LIM178'
  where iplu.limit_template_id IN (select REGEXP_SUBSTR (v_ids2, '[^,]+', 1, level) 
                          from (select rownum from dual ) 
                          connect by level &lt;= length(regexp_replace(v_ids2,'[^,]*'))+1);
  
    dbms_output.put_line('Update table 2 IDs: ' || v_ids2 || ' to LIM0178');
  
  
    end;
  </code></pre>