SQL*Plus immediately prompts for value while using &variable_name [message #489715] |
Tue, 18 January 2011 10:42  |
 |
DataMouse
Messages: 31 Registered: December 2010 Location: New York, NY - United Sta...
|
Member |
|
|
I'd like to display the question: "What is your name?", then have the user type in their name, and then display their name on the screen. However, as you can see in the code below, SQL*Plus is prompting the user to enter in a value for the your_name_input variable immediately, before the question is even asked.
I believe that this is because SQL*Plus will immediately ask for a value for a variable if it encounters an ampersand (&) sign, and this is just how it works. Is this true? How can I get around this?
SQL> SET SERVEROUTPUT ON
SQL> SET VERIFY OFF
SQL> DECLARE
2 your_name char(30);
3 BEGIN
4 dbms_output.put_line('What is your name? ');
5 your_name := '&your_name_input';
6 dbms_output.put_line('Your name is: ' || your_name);
7 END;
8 /
Enter value for your_name_input: Tiger Woods
What is your name?
Your name is: Tiger Woods
PL/SQL procedure successfully completed.
Thank you.
|
|
|
|
|
|
|
Re: SQL*Plus immediately prompts for value while using &variable_name [message #489725 is a reply to message #489720] |
Tue, 18 January 2011 11:04  |
 |
DataMouse
Messages: 31 Registered: December 2010 Location: New York, NY - United Sta...
|
Member |
|
|
Michel Cadot wrote on Tue, 18 January 2011 11:49ACCEPT your_name_input PROMPT 'What is your name? '
DECLARE
your_name char(30);
BEGIN
your_name := '&your_name_input';
dbms_output.put_line('Your name is: ' || your_name);
END;
/
Regards
Michel
Oh wow! This is perfect, thank you.
@BlackSwan Yea I know, that's just what I was set up with. Maybe I'll update my SQL*Plus version soon, but for right now, it's working OK.
|
|
|