Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Bind Variable x is not declared

Posted on 2011-09-16
6
Medium Priority
?
4,276 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 336 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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 77

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 164 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 336 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

610 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