title: plpgsql: syntax error at or near ";" LINE 66:END;
body: <p>When I was trying to create this function in the Postgres server, it gave me this weird error:</p>
  
  <blockquote>
    <p>Syntax error at or near ";"<br>
       LINE 67: END;</p>
  </blockquote>
  
  <p>Below is the code:</p>
  
  <pre><code>    CREATE OR REPLACE FUNCTION "AGMI".make_process_detail(numeric,numeric)
      RETURNS text AS
      $BODY$
  
      DECLARE
  
      i_prog_ver_id            ALIAS FOR $1;
      i_priorityMfr_checker    ALIAS FOR $2;
      i_success                text;
      i_error_message          text;
      v_rankset_Rec            record;
      v_counter                integer;
  
      BEGIN 
  
            v_counter = 304;
  
            DELETE FROM "AGMI"."PROCESSING_DETAIL"
            WHERE "PROG_VER_ID" = i_prog_ver_id;
  
            INSERT INTO "AGMI"."PROCESSING_DETAIL"("PROG_VER_ID", "RANK_SET_CODE", "PROCESS", "RUN_NUMBER", "FLAG", "START_TIME", "WHEN_DONE", "TIME_TAKEN", "PASS_NUMBER") 
            VALUES (i_prog_ver_id,0,'PMODULE',301,0,Null,Null,Null,0);
  
            IF i_priorityMfr_checker = 1 THEN
               INSERT INTO "AGMI"."PROCESSING_DETAIL"("PROG_VER_ID", "RANK_SET_CODE", "PROCESS", "RUN_NUMBER", "FLAG", "START_TIME", "WHEN_DONE", "TIME_TAKEN", "PASS_NUMBER") 
               VALUES (i_prog_ver_id,0,'PRIORITIESMFR',302,0,Null,Null,Null,0);
            ELSE IF i_priorityMfr_checker = 0 THEN
               INSERT INTO "AGMI"."PROCESSING_DETAIL"("PROG_VER_ID", "RANK_SET_CODE", "PROCESS", "RUN_NUMBER", "FLAG", "START_TIME", "WHEN_DONE", "TIME_TAKEN", "PASS_NUMBER") 
               VALUES (i_prog_ver_id,0,'PRIORITIES',302,0,Null,Null,Null,0);
            ELSE
               i_error_message := "Invalid input for 2nd entry";
               RETURN i_error_message;
            END IF;
  
            INSERT INTO "AGMI"."PROCESSING_DETAIL"("PROG_VER_ID", "RANK_SET_CODE", "PROCESS", "RUN_NUMBER", "FLAG", "START_TIME", "WHEN_DONE", "TIME_TAKEN", "PASS_NUMBER") 
            VALUES (i_prog_ver_id,0,'FMODULE',303,0,Null,Null,Null,0);
  
            FOR v_rankset_Rec IN
                  SELECT distinct "RANK_SET_CODE"
                  FROM "AGMI"."RANKSET"
                  WHERE "PROG_VER_ID" = i_prog_ver_id
                  ORDER BY "RANK_SET_CODE"
  
                  LOOP
  
             INSERT INTO "AGMI"."PROCESSING_DETAIL"("PROG_VER_ID", "RANK_SET_CODE", "PROCESS", "RUN_NUMBER", "FLAG", "START_TIME", "WHEN_DONE", "TIME_TAKEN", "PASS_NUMBER") 
             VALUES (i_prog_ver_id,v_rankset_Rec."RANK_SET_CODE",'FRANKSET',v_counter,0,Null,Null,Null,0);
  
             v_counter = v_counter+1;
  
             INSERT INTO "AGMI"."PROCESSING_DETAIL"("PROG_VER_ID", "RANK_SET_CODE", "PROCESS", "RUN_NUMBER", "FLAG", "START_TIME", "WHEN_DONE", "TIME_TAKEN", "PASS_NUMBER") 
             VALUES (i_prog_ver_id,v_rankset_Rec."RANK_SET_CODE",'NF',v_counter,0,Null,Null,Null,0);
  
             v_counter = v_counter+1;
  
             INSERT INTO "AGMI"."PROCESSING_DETAIL"("PROG_VER_ID", "RANK_SET_CODE", "PROCESS", "RUN_NUMBER", "FLAG", "START_TIME", "WHEN_DONE", "TIME_TAKEN", "PASS_NUMBER") 
             VALUES (i_prog_ver_id,v_rankset_Rec."RANK_SET_CODE",'SAT',v_counter,0,Null,Null,Null,0);
  
             v_counter = v_counter+1;
  
                 END LOOP;
  
            i_success := 'Success';
            RETURN i_success;
      END; 
      $BODY$
         LANGUAGE 'plpgsql' VOLATILE;
      ALTER FUNCTION "AGMI".make_process_detail(numeric,numeric) OWNER TO postgres;
  </code></pre>
  
  <p>Updates: The complete function is included now.</p>
  
  <p>Any idea why that is the error at the last row?</p>