PLS-00103:遇到符号“;”当期待以下之一

时间:2013-05-01 16:39:40

标签: oracle plsql

我正在尝试调试以下代码。我两次获得PLS-00103。一旦在第26行和第35行。我已经尝试注释了围绕引发没有数据发现异常的if语句和raise语句本身。我真的不知道自己哪里出错了。任何帮助将不胜感激。

   CREATE OR REPLACE PROCEDURE viewingPercentageDif
   (episodeKeyA IN NUMBER, episodeKeyB IN NUMBER)
    IS 
episodeOrderException EXCEPTION;
notConsecutiveException EXCEPTION;

preceedingEpisode NUMBER := 0;
subsequentEpisode NUMBER := 0;
percetageChange NUMBER :=0;

CURSOR episodeCursorA IS SELECT episode.ep_view_figures FROM episode WHERE episode.ep_suragate_pk = episodeKeyA;
CURSOR episodeCursorB IS SELECT episode.ep_view_figures FROM episode WHERE episode.ep_suragate_pk = episodeKeyB;

BEGIN

IF (episodeKeyA > episodeKeyB) THEN
    RAISE episodeOrderException;
END IF;

BEGIN
    OPEN episodeCursorA;
    FETCH episodeCursorA INTO preceedingEpisode;
    IF episodeCursorA%NOTFOUND THEN
        RAISE NO_DATA_FOUND;
    END IF;
    CLOSE;-- line 26
END;

BEGIN
    OPEN episodeCursorB;
    FETCH episodeCursorB INTO preceedingEpisode;
    IF episodeCursorA%NOTFOUND THEN
        RAISE NO_DATA_FOUND;
    END IF;
    CLOSE;-- line 35
END; 

-- this algorythm should be used for consective episodes only
-- need last and first episodes also
IF ((episodeKeyA + 1) = episodeKeyB) THEN
    -- check if preceeding episode viewing figure is > or < subsequent episode
    -- if preceeding episode < subequent then there has been an decrease
    IF preceedingEpisode < subsequentEpisode THEN
        percentageChange := subsequentEpisode - preceedingEpisode;
        percentageChange := (percentageChange / subsequentEpisode) * 100;

            DBMS_OUTPUT.PUT_LINE('Viewing figures have decreased by: ' || percentageChange || '%');

        -- check for increase
    ELSIF preceedingEpisode > subsequentEpisode THEN
            percentageChange := preceedingEpisode - subsequentEpisode;
            percentageChange := (percetageChange / subsequentEpisode) * 100;

            DBMS_OUTPUT.PUT_LINE('Viewing figures have increased by: ' || percentageChange || '%');
    END IF;
ELSE 
RAISE notConsecutiveException;
END IF;

    EXCEPTION 
    WHEN notConsecutiveException THEN
DBMS_OUTPUT.PUT_LINE('These episodes are not consecutive');
    WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('NO DATA FOUND');
    WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20003, 'AN ERROR WAS ENCOUNTERED');

    END viewingPercentageDif;
    /

1 个答案:

答案 0 :(得分:4)

您在关闭命令中缺少游标名称:

BEGIN
    OPEN episodeCursorB;
    FETCH episodeCursorB INTO preceedingEpisode;
    IF episodeCursorA%NOTFOUND THEN
        RAISE NO_DATA_FOUND;
    END IF;
    CLOSE;-- line 35
END; 

应该是:

BEGIN
    OPEN episodeCursorB;
    FETCH episodeCursorB INTO preceedingEpisode;
    IF episodeCursorA%NOTFOUND THEN
        RAISE NO_DATA_FOUND;
    END IF;
    CLOSE episodeCursorB;
END; 

另一个游标也一样。否则,Oracle如何知道您要关闭的光标?

有关详细信息,请参阅此链接 - Close Cursor Syntax