PLS-0013: Encoutered the symbol "C_NOTES" when expecting one of the following : :=,(@%:

Viewed 18

Does anybody know how to resolve my problem because i think the syntax is good but the compiler show me this message error. I don't know what it is because everything is correct from my pov.. these are my procedure and my package spec/body

Stand-alone procedure compiles fine

CREATE or REPLACE procedure pr_resultat
IS
   CURSOR  c_notes    is
    select avg(points) moy, num_eleve
    from resultats
    group by num_eleve;

    result varchar(20) := '';
BEGIN
   for elem in c_notes LOOP
       if elem.moy < 10 then
        result := 'failure';
       elsif elem.moy >= 10 and elem.moy < 12 then
        result := 'average';
       elsif elem.moy >= 12 and elem.moy < 14 then
        result := 'pretty good';
       elsif elem.moy >= 14 and elem.moy < 16 then
        result := 'good';
       elsif elem.moy >= 16 then
        result := 'very good';
       end if;
       DBMS_OUTPUT.PUT_LINE(elem.num_eleve || '->' || result);
   end loop;
END;
/

Package header compiles fine

create or replace package package_prcd
is
    procedure pr_resultat;
end package_prcd;
/
  

Package body results in a compile error

PLS-00103: Encountered the symbol "C_NOTES" when expecting one of the following: := . ( @ % ; in line 6

create or replace package body package_prcd
is
    procedure pr_resultat
    IS
    begin
        CURSOR  c_notes is  
        select avg(points) moy, num_eleve
        from resultats
        group by num_eleve;

        result varchar(20) := '';

        for elem in c_notes LOOP
           if elem.moy < 10 then
            result := 'failure';
           elsif elem.moy >= 10 and elem.moy < 12 then
            result := 'average';
           elsif elem.moy >= 12 and elem.moy < 14 then
            result := 'pretty good';
           elsif elem.moy >= 14 and elem.moy < 16 then
            result := 'good';
           elsif elem.moy >= 16 then
            result := 'very good';
           end if;
           DBMS_OUTPUT.PUT_LINE(elem.num_eleve || '->' || result);
        end loop;
    end;
end package_prcd;
/

Demo: https://dbfiddle.uk/lxZvALDe

1 Answers

In your package body you mistakenly moved the procedure's BEGIN before the declarations (cursor and result variable). It must come after the declarations (before the loop).

Related