title: creating clob inside for loop of PLSQL
body: <p>I have write a plsql procedure to create a html page and send it as email attachment.</p>
  
  <p>In my procedure I am writing for loop which select around 500 + records, exp code is below:</p>
  
  <pre><code>declare
  
  table clob;
  footer VARCHAR2(1000);
  
  begin
  
  table:='&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;table&gt;';
  DBMS_LOB.APPEND(table, '&lt;tr&gt;&lt;th&gt;ID&lt;/th&gt;&lt;th&gt;NAME&lt;/th&gt;&lt;/td&gt;');    
  
  footer:='&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;'
  
  for rec in (
  
  select o.id from &lt;some tables&gt; group by o.id
  
  )
  loop
  
  select 
  o.id,
  oa.name
  into id_object,name
  from
  objects o,
  objectsattributes oa
  where
  o.id=oa.object_id and
  o.id=rec.id;
  
  DBMS_LOB.APPEND(table, '&lt;tr&gt;&lt;td&gt;'||id_object||'&lt;/td&gt;&lt;td&gt;'||name||'&lt;/td&gt;&lt;/td&gt;');
  
  END LOOP;
  
  DBMS_LOB.APPEND(table,footer):
  
  
  -- send email with table as html attachment
  
  END;
  </code></pre>
  
  <p>for less amount of data it is working file and i will get html doc as attachment with proper records and layout but when data is large (in for loop) i will get repeated data in html doc and layout is also destroyed.</p>
  
  <p>i have debug it and i found that in for query I am not getting any duplicate id.</p>
  
  <p>but in html doc i am getting duplicate and some time more column.</p>
  
  <p>it seems that it has cashing issue or synchronizing issue or issue related to for loop or issue with clob writing.</p>
  
  <p>can any one tell me how to loop large abound of data and select other data base in it in for loop.</p>
  
  <p>so data will not be lost and be in sequence.</p>
  
  <p>Note : above code is for describing issue actual select statement is more complex and more data. </p>