Solved

Bind Variable x is not declared

Posted on 2011-09-16
6
3,331 Views
Last Modified: 2012-05-12
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;
0
Comment
Question by:claghorn
6 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 36549615
remove the :
declare x NUMBER;
BEGIN
  x := 1;
  PRINT x;
END;

Open in new window

0
 

Author Comment

by:claghorn
ID: 36549670
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.
0
 
LVL 73

Accepted Solution

by:
sdstuber earned 84 total points
ID: 36549767
print is a sqlplus command not a pl/sql operation

move the print outside of the pl/sql block


declare x NUMBER;
BEGIN
:x := 1;
END
PRINT x;
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 76

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 41 total points
ID: 36549784
If you want this inside the PL/SQL use: dbms_output.put_line(x);

after setting serveroutput on
0
 
LVL 73

Assisted Solution

by:sdstuber
sdstuber earned 84 total points
ID: 36550042
actually, my script above was incorrect

if you use print,  then X can't be defined within the context of the pl/sql either


variable x NUMBER;

BEGIN
:x := 1;
END

PRINT x;

Open in new window

0
 

Author Closing Comment

by:claghorn
ID: 36550838
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
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now