Solved

Bind Variable x is not declared

Posted on 2011-09-16
6
3,921 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
Technology Partners: 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
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.

707 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