rioCoder
rioCoder

Reputation: 11

Error "BIND VARIABLE "A" NOT DECLARED" when running PL/SQL block

When running the following code in Oracle 10g (pl/sql)

DECLARE 
    A NUMBER;
    B NUMBER;
BEGIN:
     A:=&N;
     B:=&M;
 IF (A>B)
     DBMS_OUTPUT.PUT_LINE('THE MAXIMUM OF TWO NUMBER IS:' || TO_CHAR(A));
 ELSE 
    DBMS_OUTPUT.PUT_LINE('THE MAXIMUM OF TWO NUMBERS IS:' || TO_CHAR(B));
 END IF;
END;

I get the error 'BIND VARIABLE "A" NOT DECLARED' and I don't know why. What is causing this?

Upvotes: 1

Views: 7298

Answers (1)

Luke Woodward
Luke Woodward

Reputation: 64959

There are a couple of things wrong with your code.

The first problem is that there should be no colon after BEGIN. What you've written is being interpreted by Oracle as BEGIN :A := ..., and that should explain why you're getting an error about bind variable A.

The second problem is with the line IF (A>B). You need to add a THEN to the end.

Incidentally, you can use GREATEST(A, B) to return the larger of two numbers.

Upvotes: 4

Related Questions