title: How to write PL/SQL to check if record exists first, before inserting
body: <p><strong><em>BACKGROUND:</em></strong> I have the tables:</p>
  
  <p><strong>TUTPRAC:</strong> CLASSID, UNITCODE, STAFFNO, CLASSDAY, CLASSTIME, CLASSTYPE, ROOMNUM</p>
  
  <p><strong>UNITSTREAM:</strong> STREAMID, UNITCODE, STAFFNO, DAY, TIME, LOCATION</p>
  
  <p><strong><em>PROBLEM:</em></strong> So i've got a database and tables and im trying to make a function that checks to see if a class is open before opening a new class, the
  procedure has to make sure that there isn't any overlaps (clash in terms of time-day or location) between
  streams (lectures), tute sessions and prac classes for that particular unit. TUTPRACS contains the records for both tutorials and practicals while UNITSTREAM containts the records for streams (Lectures).</p>
  
  <p>i also want the procedure to also
  raise an exception called CLASS_OVERLAPS that prints an alert message in case of a clash. </p>
  
  <p>I'm quite new to PL/SQL so any help would be greatly appreciated.</p>
  
  <pre><code>CREATE OR REPLACE PROCEDURE OPEN_CLASS(
             p_class IN TUTPRAC.CLASSID%TYPE,
             p_unitc IN TUTPRAC.UNITCODE%TYPE,
             p_classd IN TUTPRAC.CLASS_DAY%TYPE,
             p_classt IN TUTPRAC.CLASS_TIME%TYPE,
             p_classtp IN TUTPRAC.CLASS_TYPE%TYPE,
             p_roomnm IN TUTPRAC.ROOMNUM%TYPE)
      IS
      BEGIN
  
        INSERT INTO TUTPRAC ("CLASSID", "UNITCODE", "CLASS_DAY", "CLASS_TIME", "CLASS_TYPE", "ROOMNUM") 
        VALUES (p_class, p_unitc, p_classd, p_classt, p_classtp, p_roomnm);
  
        COMMIT;
  
      END;
  </code></pre>