title: Exception inside if condition in plsql
body: <p>I have a cursor for inserting employee data from temp table to main table. I have a scenario in which first it will check if temp table department id is exist in main department table; if <code>DeptId</code> does not exist then don't insert employee and update ERR_MSG column in temp table.  I am handling exception inside if condition after INSERT statement, but it is giving me an error like </p>
  
  <blockquote>
    <p>Encountered symbol EXCEPTION when expecting one of the following : begin,end,case,else...... </p>
  </blockquote>
  
  <p>sample code is as below:-</p>
  
  <pre><code>DECLARE
   --var list
  
      BEGIN
       OPEN ltempCur For
  
           -- here i am selecting cols from temp table in variables
  
       LOOP
          FETCH ltempCur 
       INTO 
         --all the declared variables here
       EXIT
      WHEN ltempCur %NOTFOUND;
      BEGIN
  
       --select statement for checking if employee record exist in table
  
       IF(lExist == 0)  --if emloyee record not exist
       THEN
  
         begin
           --check if dept exist in dept table if not exist then i have assigned zero to deptid variable in NO_DATA_FOUND exception
         end;
  
         IF(vardeptid &gt; 0)  --if condition for which i have mentioned in description
  
         --Insert statement for employee
  
         EXCEPTION
         WHEN OTHERS
         THEN
             --handling exp
         COMMIT;
      END;         
  
         END IF; -- dept id check if end
  
       --end loop -- close cursor
  </code></pre>
  
  <p>In above code, if I remove <code>deptid</code> IF  ELSE condition then it is working fine, but with that IF condition it is giving error </p>