Reputation: 43
I have been trying to display only the odd numbers between two user entered numbers by checking if both the numbers are positive. Here's my pl/sql block :
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;
/
But i keep getting error : PLS-00103: Encountered the symbol ";" when expecting one of the following:
at line 15;
even though after multiple checks I cannot find where the problem is.
Any help will be great.
Upvotes: 0
Views: 101
Reputation: 143103
Several errors.
ELSE
instead of ELSIF
Mistakes have been commented (see code below).
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>
Upvotes: 1