尝试创建PL / SQL过程时出现ORA-06550错误

时间:2016-07-24 15:52:18

标签: oracle plsql

有些东西已经关闭,但无法弄清楚我错过了什么?

 select 
        grade.sectionid,
        grade.studentid,
        course.courseid
    FROM section
        INNER JOIN grade
                ON grade.sectionid = section.sectionid
        INNER JOIN course
                ON course.courseid = section.courseid;




DECLARE
   CURSOR mycursor is
      select 
        sectionid, studentid, courseid, coursename
      FROM grade, course, section;      
   var_secID NUMBER(10);
   var_studentID NUMBER (10);
   var_gradeLetter CHAR(1);
   var_coursetitle VARCHAR2(25);


BEGIN
   OPEN mycursor;
LOOP
      FETCH mycursor 
      INTO var_secID, var_studentID, var_gradeLetter, var_coursetitle;
      EXIT WHEN mycursor%NOTFOUND;  
      If var_coursetitle(coursename,1) BETWEEN A AND F then
      UPDATE grade
        SET grade = 'A'
        WHERE sectionid;
        END IF;
END LOOP;
CLOSE mycursor;
END;
/

继续收到此错误:

第21行的错误:

ORA-06550:第21行,第18栏:

PL / SQL:ORA-00920:无效的关系运算符

ORA-06550:第19行,第4栏:

PL / SQL:忽略SQL语句

2 个答案:

答案 0 :(得分:1)

BETWEEN A AND F then

也许应该是:

BETWEEN 'A' and 'F' then

答案 1 :(得分:0)

你可以在没有任何PL / SQL的情况下完成,如:

update grade g set grade = 'A'
where  g.sectionid in
       ( select s.sectionid from section s
                join course c on c.courseid = s.courseid
         where  substr(c.coursename,-1, 1) between 'A' and 'F' );

然而,作为PL / SQL学习练习,您可以在没有任何变量或游标管理的情况下完成:

begin
    for r in (
        select g.sectionid, g.studentid, c.courseid, c.coursename
             , substr(c.coursename,-1, 1) as course_lastchar
        from   grade g
               join section s on s.sectionid = g.sectionid
               join course c on c.courseid = s.courseid
        for update of grade
    )
    loop
        if r.course_lastchar between 'A' and 'F' then
            update grade set grade = 'A' where sectionid = r.sectionid;
        end if;
    end loop;
end;

(顺便说一下,养成使用一致的缩进大小整齐排列代码的习惯。)