Skip to content
Advertisement

SP2-0552: Bind variable “N3” not declared

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 be n2:=&n2;
  • else if should be elsif (or, if you want to keep the else if then you need a second end if; to terminate that second if 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;
/
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement