1

Please help me to create a bind variable

I'm doing like this

SELECT Period FROM POWER WHERE Period = :F1;

EXEC :F;

Result: Shows Null Values.

Period column is of Date datatype.

Lukasz Szozda
  • 162,964
  • 23
  • 234
  • 275
drill
  • 134
  • 1
  • 12
  • Where are you running this? SQL*Plus / Toad / somewhere else? – Boneist Oct 07 '15 at 15:19
  • you have to init F1. declare it, give it a value. if you want to be prompted for a value, use a IDE like SQL Developer. you'll get prompted in SQL*Plus if you use &F1 - but that's not a bind. – thatjeffsmith Oct 07 '15 at 15:33
  • 1
    If you are using SQL*Plus, there are a number of posts that address bind variable usage. I really like Alex Poole's answer with this one, http://stackoverflow.com/questions/11737849/declare-bind-variables-in-sqlplus. – Patrick Bacon Oct 07 '15 at 15:35
  • Thanks *8-) The syntax in that answer works in SQL Developer too. Not sure about other clients. In this case you should also have an explicit `to_date()` around the bind variable, which will be a string, and specify the expected format. – Alex Poole Oct 07 '15 at 16:22
  • @Boneist, I'm using in oracle sql developer – drill Oct 07 '15 at 18:01
  • @Ashish - the linked answer works in SQL Developer too. Has that, or any of the other answers about bind variables, solved your issue? – Alex Poole Oct 08 '15 at 08:16
  • @AlexPoole NO alex..am still struggling with my issue. – drill Oct 08 '15 at 08:48
  • @Ashish - then you'll need to edit your question to explain what you are trying and why it isn't working for you. As written it looks like a pretty good match. I'm not sure what the `exec` is doing though; you can't use a bind variable for an entire PL/SQL statement. Include what you want the bind values to be set to an what you'll do with the and the results. – Alex Poole Oct 08 '15 at 08:52

0 Answers0