title: PL/SQL Cursor If No Data & Output
body: <pre><code>CREATE OR REPLACE procedure verify_data
  IS
  cursor c1 is 
  select 
    e.id
  from 
    table1 e 
  where 
    id IN (select id from table1)
    and id in (select id from table2);
  BEGIN
  FOR ed in c1
     LOOP
        DBMS_OUTPUT.PUT_LINE(ed.id||ed.name);
     END LOOP;
  END;
  /
  </code></pre>
  
  <p>When i execute this PL/SQL , it output as </p>
  
  <p>14Andrew R. Smith</p>
  
  <p>I want to ask is how do i make it output as a normal result like this with the formating etc.. and also </p>
  
  <p>Below is what happen if i run the select statement directly with at terminal</p>
  
  <pre><code>        ID NAME
  ---------- --------------------------------------------------
          14 Andrew R. Smith
  </code></pre>
  
  <p><strong>First Question:</strong>
  How to make my DBMS_OUTPUT.PUT_LINE same as what appear on terminal. like the ID then below is the ID data , and NAME etc.</p>
  
  <p><strong>Next Question:</strong></p>
  
  <p>I want to ask is</p>
  
  <p>how do i do a output that if cursor is empty or no result, i DBMS_OUTPUT.PUT_LINE("NO RECORDS");</p>
  
  <p><strong>Thanks for all help!!</strong></p>
  
  <p><strong>Update:</strong></p>
  
  <p>I did this</p>
  
  <pre><code>CREATE OR REPLACE procedure verify_data
  IS
  cursor c1 is 
  select 
    e.id
  from 
    table1 e 
  where 
    id IN (select id from table1)
    and id in (select id from table2);
  BEGIN
  FOR ed in c1
     LOOP
        DBMS_OUTPUT.PUT_LINE(ed.id||ed.name);
  
   if c1%notfound then
   DBMS_OUTPUT.PUT_LINE('Okay');
    end if;
  
  END LOOP;
  
  END;
  </code></pre>
  
  <p>But it does not <strong>print Okay</strong> when no record is fetch from the PL/SQL. I added the c1%notfound to after END LOOP</p>