Hi,<br><br> How to declare a variable in the<br>SQL>Prompt and use the same in any PL/SQL<br>Block.Hope got my question.<br><br>Thanks in advance<br>Motto
If you mean from within SQL*Plus:<br>'SET DEFINE ON' and then prefix your variable names with '&', eg.<br> SELECT column1<br> FROM table<br> WHERE column2 = '&my_variable'<br>SQL*Plus will prompt you for the value every time it runs.<br>If you use '&&' as a prefix the variable will be kept for the<br>remainder of the SQL*Plus session.<br><br>I hope this answers your question.
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.<br>To declare a PL/SQL variable in SQL*Plus, use the variable command, then reference it using a colon, e.g.<FONT FACE=monospace><br>SQL> variable a number;<br>SQL> execute :a := 2;<br><br>PL/SQL procedure successfully completed<br><br>SQL> print a<br><br> A<br>---------<br> 2<br><br>SQL> select :a * 4 from sys.dual;<br><br> :A*4<br>---------<br> 8<br><br>SQL></font><br>I hope this helps.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.