How to create a menu in SQLPlus or PL/SQL

后端 未结 6 1653
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-11 22:15

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

6条回答
  •  长情又很酷
    2020-12-11 23:05

    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.

提交回复
热议问题