pl -00103在pl/sql中出现了这个错误



我一直试图通过检查两个数字是否都是正数来仅显示两个用户输入的数字之间的奇数。下面是我的pl/sql块:

declare 
num1 number(3);
num2 number(3);
begin
num1 := &num1;
num2 := &num2;

if (num1 > 0 and num2 > 0) then
dbms_output.put_line('Both entered numbers are positive');
dbms_output.put_line('The odd numbers between the two entered positive numbers are : ');
for i in num1..num2 loop
if mod(i,2)=0 then
dbms_output.put_line();
elsif
dbms_output.put_line(i);
end if;
i := i+1;
end loop;
elsif 
dbms_output.put_line('Both entered numbers are not positive');
end if;
end;
/

但是我一直得到错误:PLS-00103: Encountered the symbol ";" when expecting one of the following:在第15行;即使经过多次检查,我也找不到问题所在。任何帮助都太好了。

几个错误

  • 应该是ELSE而不是ELSIF
  • 你不能/不应该手动增加FOR循环计数器;Oracle会自动执行

错误已被注释(见下面的代码)。

SQL> set serveroutput on
SQL> declare
2      num1 number(3);
3      num2 number(3);
4  begin
5      num1 := &num1;
6      num2 := &num2;
7
8      if (num1 > 0 and num2 > 0) then
9          dbms_output.put_line('Both entered numbers are positive');
10          dbms_output.put_line('The odd numbers between the two entered positive numbers are : ');
11          for i in num1..num2 loop
12              if mod(i,2)=0 then
13              dbms_output.put_line(null);
14              else --elsif
15              dbms_output.put_line(i);
16              end if;
17          --i := i+1;
18          end loop;
19      else --elsif
20          dbms_output.put_line('Both entered numbers are not positive');
21      end if;
22
23  end;
24  /
Enter value for num1: 5
Enter value for num2: 10
Both entered numbers are positive
The odd numbers between the two entered positive numbers are :
5
7
9
PL/SQL procedure successfully completed.
SQL>

相关内容

  • 没有找到相关文章

最新更新