title: PLS-00103: Encountered the symbol "THEN" when expecting one of the following
body: <p>i am trying to run this code but it gives me an error in "THEN", i have checked all the code line by line and it appears that the error is in the if statement but i double checked it.</p>
  
  <p>i am trying to compare the time of the accident so i can be able to send the ambulance to the the accident which happened first. i would appreciate your help</p>
  
  <pre><code>`create or replace function get_loc return location is
  max NUMBER;
  CURSOR accident_records IS
  SELECT * FROM NEW_ACCIDENT;
  accidentRec NEW_ACCIDENT_TYPE := NEW_ACCIDENT_TYPE (NULL,NULL,NULL,NULL);
  ac_loc LOCATION := LOCATION (NULL,NULL);
  type New_accident_rec_type is record
  (
  id number,
  loc location,
  TIME NUMBER,
  SITUATION varchar2(60)
  );
  new_accident_rec New_accident_rec_type;
  BEGIN
  max:=0;
  OPEN accident_records;
  LOOP FETCH accident_records INTO new_accident_rec;
  EXIT WHEN accident_records%NOTFOUND;
  IF new_accident_rec.situation='not handled' then
  IF new_accident_rec.time&gt;max THEN
  max:=new_accident_rec.time;
  accidentRec.time:=new_accident_rec.time;
  ac_loc:=new_accident_rec.loc;
  END IF;
  IF new_accident_rec.time&lt;max THEN
  ac_loc:=NULL;
  END IF;
  END IF;
  END LOOP;
  CLOSE accident_records;
  dbms_output.put_line ('The time of Accident is: '||accidentRec.time || 'The location of the accident is: ' ||ac_loc);
  RETURN ac_loc;
  END;`
  </code></pre>