I am doing a PL/SQL script that will get input from an user, and then it will find out through an if statement if it has to add data to 1 or 2 tables. I am using IF statements and a WHILE loop to accomplish this task, but it isn't working properly. Also this script it's part of a main menu. Any input is appreciated it.
-- q3.sql
-- Question name goes here!!
VARIABLE g_options VARCHAR2(1000);
PROMPT 'Vehicle Inventory Record'
ACCEPT p_Options PROMPT 'Does this car has any Optional Equipment or Accessories?(YES or NO)';
-- Option table
ACCEPT p_OCode PROMPT 'Enter the code for the option picked (Ex. CD2):'
ACCEPT p_ODescription PROMPT 'Enter the description for the option picked:'
ACCEPT p_OPrice PROMPT 'Enter the price for the option picked:'
-- Car table
ACCEPT p_SerialNo PROMPT 'What is the serial number of the car?'
ACCEPT p_Make PROMPT 'What is the make of the car?'
ACCEPT p_Model PROMPT 'What is the model of the car?'
ACCEPT p_Year PROMPT 'What is the color of the car?'
ACCEPT p_Trim PROMPT 'What is the trim of the car?'
ACCEPT p_PurchFrom PROMPT 'Where was the car purchased from?'
ACCEPT p_PurchInvNo PROMPT 'What was the invoice number of the purcahse?'
ACCEPT p_PurchDate PROMPT 'When was the car purcahsed?(ex. 13-FEB-06)'
ACCEPT p_PurchCost PROMPT 'How much did he car cost?'
ACCEPT p_ListPrice PROMPT 'What was the list price of the car?'
DECLARE
n_numb number := 1;
BEGIN
--WHILE n_numb < 2 LOOP
IF '&p_Options' = 'YES' THEN
:g_options := 'Input will be added into the option table AND car table';
-- Insert statement goes here
n_numb := 2;
ELSIF '&p_Options' = 'NO' THEN
:g_options := 'Input will only be added to the car table';
-- Insert statement goes here
n_numb := 2;
ELSE
:g_options := ' The correct input for the first prompt was "YES" or "NO", you entered something else'
--:g_options := :g_options || ' The script will now end, please run it again'
n_numb := 0;
END IF;
--END LOOP;
END;
/
I commented the loop out, and the n_numb variable, and I get this error:
END IF;
*
ERROR at line 22:
ORA-06550: line 22, column 7:
PLS-00103: Encountered the symbol "END" when expecting one of the following:
. ( * @ % & = - + ; < / > at in is mod remainder not rem
<an exponent (**)> <> or != or ~= >= <= <> and or like
between || multiset member SUBMULTISET_
The symbol ";" was substituted for "END" to continue.
UPDATE 1: I added the semicolon at the end of the statement, but then I got an error saying that p_Options had to be declared.I just changed p_Options to '&p_Options', and it says that the script ran successfully, BUT I don't see any output. Like:' The script will now end, please run it again' .
This is all I see!
old 7: IF '&p_Options' = 'YES' THEN
new 7: IF '' = 'YES' THEN
old 12: ELSIF '&p_Options' = 'NO' THEN
new 12: ELSIF '' = 'NO' THEN
PL/SQL procedure successfully completed.
UPDATE 2: I got the if statement to work. BUT the loop will not work if I were to type something other than YES or NO as an input. I basically get no return, and I can keep on going pressing enter forever. :S
------------On a different note----------
How do I extract the information that the user/s entered and add it into a table using an INSERT statement?