Solved

Bind Variable x is not declared

Posted on 2011-09-16
6
3,819 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 143

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 74

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 77

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 74

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

739 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