문제

So, I've done some researching and from what I can find of similar problems, I cannot solve my particular issue. I'm encountering the dreaded,

Error(35,18): PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: ( begin case declare end exception exit for goto if loop mod null pragma raise return select update while with << continue close current delete fetch lock insert open rollback savepoint set sql execute commit for all merge pipe purge

Some of the fixes were to look through your code and find any left off semi-colons. The problem with that for my particular code is that without the declaration as a stored procedure and the IN parameter, the code works perfectly. I'm taking a procedure that works and just trying to be able to change what is being searched without hardcoding a whole new search. Does that make sense?

Here is the code: `

CREATE OR REPLACE PROCEDURE testProcedure(var_Name IN varchar2)
IS
BEGIN
DECLARE
    var_Name newscores.name%TYPE;
    var_courseNo newscores.courseNo%Type;
    var_sectionNo newscores.sectionNo%Type;
    var_average grade2.average%TYPE;
    var_termscores gradepolicy.lettergrade%TYPE;
CURSOR AverageCursor is
    SELECT distinct n.name, n.courseNo, n.sectionNo, g2.average, gp.lettergrade
from newscores n, grade2 g2, gradepolicy gp
where n.stuNo = g2.stuNo
and n.courseNo = g2.courseNo
and n.sectionNo = g2.sectionNo
and g2.average < gp.upper_bound
and g2.average > gp.low_bound
and n.name = 'Randy Ballard'
and gp.classNo = g2.courseNo
and gp.sectionNo = g2.sectionNo;
BEGIN
OPEN AverageCursor;
LOOP

    FETCH AverageCursor
      INTO var_Name, var_courseNo, var_SectionNo, var_average, var_termscore;
    Exit when AverageCursor%NOTFOUND;

    dbms_output.put_line('Full Name'||' '||var_Name);
    dbms_output.put_line('Full Name'||' '||var_courseNo);
    dbms_output.put_line('Full Name'||' '||var_sectionNo);
    dbms_output.put_line('Full Name'||' '||var_average);
    dbms_output.put_line('Full Name'||' '||var_termscore);
END LOOP;
END testProcedure;
/

`

도움이 되었습니까?

해결책

The DECLARE keyword and extra BEGIN are causing your error. Try this:

CREATE OR REPLACE PROCEDURE testProcedure(p_name IN VARCHAR2)
IS
    var_Name newscores.name%TYPE;
    var_courseNo newscores.courseNo%Type;
    var_sectionNo newscores.sectionNo%Type;
    var_average grade2.average%TYPE;
    var_termscores gradepolicy.lettergrade%TYPE;
    CURSOR AverageCursor is
        SELECT distinct n.name, n.courseNo, n.sectionNo, g2.average, gp.lettergrade
          from newscores n, grade2 g2, gradepolicy gp
          where n.stuNo = g2.stuNo
            and n.courseNo = g2.courseNo
            and n.sectionNo = g2.sectionNo
            and g2.average < gp.upper_bound
            and g2.average > gp.low_bound
            and n.name = p_name
            and gp.classNo = g2.courseNo
            and gp.sectionNo = g2.sectionNo;
BEGIN
  OPEN AverageCursor;
  LOOP

      FETCH AverageCursor
        INTO var_Name, var_courseNo, var_SectionNo, var_average, var_termscore;
      Exit when AverageCursor%NOTFOUND;

      dbms_output.put_line('Full Name'||' '||var_Name);
      dbms_output.put_line('Full Name'||' '||var_courseNo);
      dbms_output.put_line('Full Name'||' '||var_sectionNo);
      dbms_output.put_line('Full Name'||' '||var_average);
      dbms_output.put_line('Full Name'||' '||var_termscore);
  END LOOP;
END testProcedure;
/

Normally you declare your variables between the IS and the BEGIN keywords.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top