Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> Re: plsql prompt for input
Hello Maryann,
If you can find a copy of my SQL*Plus book, read the two chapters on scripting. There are some tricks you can play with SQL*Plus to get it to branch depending on whether a user response with Y or an N.
You really can't prompt for input from PL/SQL. You attempt to do this below via &&Response, but it is actually SQL*Plus that prompts for that variable. The true sequence of events is:
You might try something along these lines:
ACCEPT Emp_ID Prompt 'Please Enter the Employee ID > ' ACCEPT Response Prompt 'Is &Emp_ID correct (y/n)?> ' @somefile_&Response
Ok. The key here is to be sure you have two script files, one named somefile_y.sql, and the other named somefile_n.sql. The user's y/n response then determines which of those files is executed. I don't show it, but there are some things you can do to validate that y/n response, and make it case-insensitive, if those things are important to you.
SQL*Plus isn't the world's most robust scripting tool.
Best regards,
Jonathan Gennick --- Brighten the corner where you are http://Gennick.com * 906.387.1698 * mailto:jonathan@gennick.com
Join the Oracle-article list and receive one article on Oracle technologies per month by email. To join, visit http://four.pairlist.net/mailman/listinfo/oracle-article, or send email to Oracle-article-request_at_gennick.com and include the word "subscribe" in either the subject or body.
Tuesday, February 17, 2004, 7:03:37 PM, Maryann Atkinson (maryann_30_at_yahoo.com) wrote:
MA> I am trying to write a pl/sql script that will prompt the user for an id, MA> and then somehow I need to re-prompt the user to verify that indeed MA> this is the correct id. MA> The one below seems like it should work, except because of buffer issue(I MA> guess)
MA> thx
MA> maa
MA> SET VERIFY OFF
MA> ACCEPT Emp_ID Prompt 'Please Enter the Employee ID > '
MA> DECLARE
MA> Response VARCHAR2(1);
MA> BEGIN
MA> DBMS_Output.Put_Line('Employee ID entered is ' || &Emp_ID MA> || '. Is this correct?(Y/N)'); MA> Response := &&Response; MA> DBMS_Output.Put_Line('Response is ' || Response);MA> END;
MA> ---------------------------------------------------------------- MA> Please see the official ORACLE-L FAQ: http://www.orafaq.com MA> ---------------------------------------------------------------- MA> To unsubscribe send email to: oracle-l-request_at_freelists.org MA> put 'unsubscribe' in the subject line. MA> -- MA> Archives are at http://www.freelists.org/archives/oracle-l/MA> FAQ is at http://www.freelists.org/help/fom-serve/cache/1.html
MA> -----------------------------------------------------------------Please see the official ORACLE-L FAQ: http://www.orafaq.com
----------------------------------------------------------------
![]() |
![]() |