If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > reading user input?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-28-02, 17:33
easyRider easyRider is offline
Registered User
 
Join Date: Aug 2002
Posts: 1
reading user input?

Hi,
I have the following problem - how to read user input from the command line? Can this be done using only PL/SQL and SQL?

Here is an example. First I want to read the "user choice", and if it is 1, read the value for "a", if it is 2 - read the value for "b". But when I execute the code below (from sql window), it prompts me to enter the "user choice" and after that, regardless of my input prompts me to enter BOTH "a" AND "b". After that, it executes only the statements (not shown in the code) for corresponding "user_choice". Someone told me that "the precompiler looks for the & symbol when parsing the code and does the prompts". Is there a way around it?


VARIABLE user_cho NUMBER
ACCEPT user_cho PROMPT 'Enter your choice: '

DECLARE
user_choice NUMBER := &user_cho;
a NUMBER := 0;
b NUMBER := 0;

BEGIN
IF(user_choice = 1)
THEN
a := &a;
ELSIF(user_choice = 2)
THEN
b := &b;
END IF;
END;
/

Thanks,
e.
Reply With Quote
  #2 (permalink)  
Old 09-10-02, 11:24
Sef Sef is offline
Registered User
 
Join Date: Aug 2002
Location: Kampala, Uganda - East Africa
Posts: 13
Re: reading user input?

In case you want to pass the input to an SQL statement as parameters, then u may as well use;

'&VAR1'

EG.

SELECT NAME
FROM EMPLOYEE
WHERE CODE = '&VAR1'
AND GRADE = '&VAR2';

The user will be prompted with,
Enter value for var1:

Once that has been entered, he/she will be prompted to enter the next, var2. Then the query will execute.


Sef
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On