Hi
I'm quite new to Oracle development and especially in how to master scripting and SQL *Plus.
To be able to better understand the PROMPT, ACCEPT, VARIABLE, DEFINE commands etc. I have setup the following scenario.
I want to create a script that enables the user to choose an option from a menu.
1. Add name (Id, firstname, lastname, city)
2. List all names
3. Delete a name
This is how I'm thinking of writing my implementation
SET SERVEROUTPUT ON;
PROMPT '1. Add a name';
PROMPT '2. List all names';
PROMPT '3. Delete a name';
PROMPT '4. Exit';
ACCEPT myopt NUMBER PROMPT 'Enter option';
DECLARE
BEGIN
IF &myopt = 1 THEN
/*
How can I move the control back to
SQL*Plus so that I can prompt the
user to input FIRSTNAME, LASTNAME and CITY
using ACCEPT?
*/
ELSIF &myopt = 2 THEN
-- Call procedure printNames.
printNames
ELSIF &myopt = 3 THEN
-- Here I have similar problem to option 1.
I want to prompt the user for
an ID and then run a delete query
ELSIF &myopt = 4 THEN
-- How to exit app?
END IF
END
-- After an user have selected an option how can I get the menu to retain control over the app?
Thanks
Erik
I'm quite new to Oracle development and especially in how to master scripting and SQL *Plus.
To be able to better understand the PROMPT, ACCEPT, VARIABLE, DEFINE commands etc. I have setup the following scenario.
I want to create a script that enables the user to choose an option from a menu.
1. Add name (Id, firstname, lastname, city)
2. List all names
3. Delete a name
This is how I'm thinking of writing my implementation
SET SERVEROUTPUT ON;
PROMPT '1. Add a name';
PROMPT '2. List all names';
PROMPT '3. Delete a name';
PROMPT '4. Exit';
ACCEPT myopt NUMBER PROMPT 'Enter option';
DECLARE
BEGIN
IF &myopt = 1 THEN
/*
How can I move the control back to
SQL*Plus so that I can prompt the
user to input FIRSTNAME, LASTNAME and CITY
using ACCEPT?
*/
ELSIF &myopt = 2 THEN
-- Call procedure printNames.
printNames
ELSIF &myopt = 3 THEN
-- Here I have similar problem to option 1.
I want to prompt the user for
an ID and then run a delete query
ELSIF &myopt = 4 THEN
-- How to exit app?
END IF
END
-- After an user have selected an option how can I get the menu to retain control over the app?
Thanks
Erik