Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

bind variables and "declare" error

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I am trying to use a simple SQL to test the usage of bind variables.

select empl_name from empl_tbl where emp_id = :ABC;

I get an error:


Bind variable "ABC" not declared.

Can someone help. I am not a DBA, just a programmer new to SQL Plus and Oracle. Thanks.

-Ken
 

If you are using sqlplus, you can use & instead.

For example;

SQL> select empl_name from empl_tbl where emp_id = &ABC;

Robbie

"The rule is, not to besiege walled cities if it can possibly be avoided" -- Art of War
 
The difference between those statements is that Rcurva's one will be parsed every time before execution (substituting or lexical variable). The real "bind" variable should be declared and possibly initialized:

var[iable] abc number
exec[ute] :abc:=1
select empl_name from empl_tbl where emp_id = :ABC;




 
OK, I tried both.

Robbie, yours worked great as a prompt for the value is what I was looking for.

REM, your code on my machine would not prompt for values (this is what I was looking for in bind variables). However, is there a way to prompt for values AND eliminate the redundant parsing (which is also of interest to me)?

-Ken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top