Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

oracle - How to create a menu in SQLPlus or PL/SQL

I have several scripts that I would like to start from a menu presented to the SQLPlus user. Something like:

Please make a selection:
1: Do script a
2: Do script b
3: Do script c

I just need a point in the right direction, not a quick answer.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here is a SQL Plus script to do that:

prompt Please make a selection:
prompt 1: Do script a
prompt 2: Do script b
prompt 3: Do script c

accept selection prompt "Enter option 1-3: "

set term off

column script new_value v_script

select case '&selection.'
       when '1' then 'script_a'
       when '2' then 'script_b'
       when '3' then 'script_c'
       else 'menu'
       end as script
from dual;

set term on

@&v_script.

NB The 'menu' in the ELSE part of the case expression is the name of this script, so that it runs itself again when the user enters an invalid option.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...