Link to home
Start Free TrialLog in
Avatar of claghorn
claghorn

asked on

Bind Variable x is not declared

I get Bind Variable "x" is NOT DECLARED
anonymous block completed
when running the following program.

Can you show me how to declare this so this program will print the value?

declare x NUMBER;
BEGIN
:x := 1;
PRINT :x;
END;
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

remove the :
declare x NUMBER;
BEGIN
  x := 1;
  PRINT x;
END;

Open in new window

Avatar of claghorn
claghorn

ASKER

It did'nt work. Does it work for you?

SQL> declare x NUMBER;
  2  BEGIN
  3    x := 1;
  4    PRINT x;
  5  END;
  6  /
  PRINT x;
        *
ERROR at line 4:
ORA-06550: line 4, column 9:
PLS-00103: Encountered the symbol "X" when expecting one of the following:
:= . ( @ % ;
The symbol ":=" was substituted for "X" to continue.
ASKER CERTIFIED SOLUTION
Avatar of Sean Stuber
Sean Stuber

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks. My book has some disfunctional code so I had to ask for help on such a seemingly trivial thing. Here's the summary.

SQL> help print

 PRINT
 -----

 Displays the current values of bind variables, or lists all bind
 variables.

 PRI[NT] [variable ...]

--works
SQL> set serveroutput on;
SQL> declare x NUMBER;
  2  BEGIN
  3  x := 1;
  4  dbms_output.put_line(x);
  5  END;
  6  /
1

PL/SQL procedure successfully completed.

--works
SQL> variable x NUMBER;
SQL> BEGIN
  2  :x := 1;
  3  END;
  4  /

PL/SQL procedure successfully completed.

SQL> print x;

         X
----------
         1