plpgsql:语法错误在或附近&#34 ;;"第66行:结束;

时间:2016-02-03 19:17:49

标签: postgresql plpgsql

当我尝试在Postgres服务器中创建此功能时,它给了我这个奇怪的错误:

  

语法错误在或附近&#34 ;;"
     第67行:结束;

以下是代码:

    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;

更新:现在包含完整的功能。

知道为什么那是最后一行的错误吗?

2 个答案:

答案 0 :(得分:2)

ELSE IF i_priorityMfr_checker = 0 THEN

需要

ELSIF i_priorityMfr_checker = 0 THEN

http://www.postgresql.org/docs/current/static/plpgsql-control-structures.html#PLPGSQL-CONDITIONALS

答案 1 :(得分:0)

ELSEIF也有效(中间有' E')。