如何在SQLPlus或PL/SQL中创建菜单 [英] How to create a menu in SQLPlus or PL/SQL

查看:91
本文介绍了如何在SQLPlus或PL/SQL中创建菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个脚本,我想从提供给SQLPlus用户的菜单开始.像这样的东西:

请选择:
1:编写脚本
2:执行脚本b
3:执行脚本c

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.

推荐答案

以下是执行此操作的SQL Plus脚本:

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案例表达式的ELSE部分中的菜单"是此脚本的名称,因此当用户输入无效的选项时,它将再次运行.

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.

这篇关于如何在SQLPlus或PL/SQL中创建菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆