Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Usage of Variable in the sql Prompt

Usage of Variable in the sql Prompt

Usage of Variable in the sql Prompt


   How to declare a variable in the
SQL>Prompt and use the same in any PL/SQL
Block.Hope got my question.

Thanks in advance

RE: Usage of Variable in the sql Prompt

If you mean from within SQL*Plus:
'SET DEFINE ON' and then prefix your variable names with '&', eg.
   SELECT column1
   FROM   table
   WHERE  column2 = '&my_variable'
SQL*Plus will prompt you for the value every time it runs.
If you use '&&' as a prefix the variable will be kept for the
remainder of the SQL*Plus session.

I hope this answers your question.

RE: Usage of Variable in the sql Prompt

The use of & or && as variable markers may not be what you want here. These will simply perform text substitution within a SQL*Plus script. If you want to reference your value from within a PL/SQL stored procedure for example, you'll need to declare a bind variable.
To declare a PL/SQL variable in SQL*Plus, use the variable command, then reference it using a colon, e.g.
SQL> variable a number;
SQL> execute :a := 2;

PL/SQL procedure successfully completed

SQL> print a


SQL> select :a * 4 from sys.dual;



I hope this helps.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close