0

PL\SQL で複数のif条件を使用しようとすると、エラーが発生します。

ORA-06550: line 16, column 5:
PLS-00103: Encountered the symbol "LOOP" when expecting one of the following:
   if

ここに私のコードがあります:

    declare
price_var number;
st_numb number;
co_pr number;
cursor student_count is select STUDENT_NUMBER,COURSE_PRICE from COURSES;
begin
open student_count;
loop
fetch student_count into st_numb,co_pr;
if st_numb<10 then
update COURSES set COURSE_PRICE=co_pr*1.05;
elseif st_numb>10 then
update COURSES set COURSE_PRICE=co_pr*1.07;
end if;
exit when student_count%notfound;
end loop;
end

エラーがどこにあるか教えてもらえますか? ありがとう。

4

3 に答える 3

4

まず、PL/SQL では「elseif」ではなく「elsif」だと思います。次に(これが重要かどうかはわかりません)、条件を括弧で囲む必要があるかもしれませんが、わかりません。

ソース: https://www.tutorialspoint.com/plsql/plsql_if_then_elsif.htm

于 2016-10-30T22:19:07.780 に答える
1

必要がありますelsif, notelseifおよび;after end. これを修正してみてください:

declare
  price_var number;
  st_numb   number;
  co_pr     number;
  cursor student_count is
    select student_number
          ,course_price
      from courses;
begin
  open student_count;
  loop
    fetch student_count
      into st_numb
          ,co_pr;
    if st_numb < 10 then
      update courses set course_price = co_pr * 1.05;
    elsif st_numb > 10 then   --elsif, not elseif
      update courses set course_price = co_pr * 1.07;
    end if;
    exit when student_count%notfound;
  end loop;
end;  --also need ";" after end 
于 2016-10-31T08:23:26.847 に答える