This is a code for comparing three numbers and to print the greatest value.
declare n1 number(2); n2 number(2); n3 number(2); begin n1:=&n1; n2:=&n2: n3:=&n3; if n1>n2 and n1>n3 then dbms_output.put_line('The greatest number is n1 '||n1); else if n2>n1 and n2>n3 then dbms_output.put_line('The greatest number is n2 '||n2); else dbms_output.put_line('The greatest number is n3 '||n3); end if; end; /
When i try to run this pl sql code in oracle it says
old 6: n1:=&n1; new 6: n1:=4; Enter value for n2: 5 old 7: n2:=&n2: new 7: n2:=5: Enter value for n3: 6 old 8: n3:=&n3; new 8: n3:=6; SP2-0552: Bind variable "N3" not declared.
Can u tell me where it is wrong???I would be very grateful
Advertisement
Answer
You have 3 errors (typos):
- You need the
DECLARE
keyword before you start declaring variables. n2:=&n2:
should ben2:=&n2;
else if
should beelsif
(or, if you want to keep theelse if
then you need a secondend if;
to terminate that secondif
statement)
DECLARE n1 number(2); n2 number(2); n3 number(2); begin n1:=&n1; n2:=&n2; n3:=&n3; if n1>n2 and n1>n3 then dbms_output.put_line('The greatest number is n1 '||n1); elsif n2>n1 and n2>n3 then dbms_output.put_line('The greatest number is n2 '||n2); else dbms_output.put_line('The greatest number is n3 '||n3); end if; end; /