如何在运行时从用户获取输入 [英] how to get input from user at runtime

查看:48
本文介绍了如何在运行时从用户获取输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在oracle 10g pl/sql块中获取用户的运行时输入(即与用户进行交互通信),

i want to take runtime input from user in oracle 10g pl/sql blocks(i.e. interactive communication with user), is it possible?

declare
x number;
begin
x=&x;
end

此代码将错误显示为&不能在oracle 10g中使用.

this code gives error as & can't be used in oracle 10g.

推荐答案

要读取用户输入并将其存储在变量中,以供以后使用,可以使用SQL * Plus命令ACCEPT.

To read the user input and store it in a variable, for later use, you can use SQL*Plus command ACCEPT.

Accept <your variable> <variable type if needed [number|char|date]> prompt 'message'

示例

accept x number prompt 'Please enter something: '

然后可以在PL/SQL块中使用x变量,如下所示:

And then you can use the x variable in a PL/SQL block as follows:

declare 
  a number;
begin
  a := &x;
end;
/

使用字符串示例:

accept x char prompt 'Please enter something: '

declare 
  a varchar2(10);
begin
  a := '&x';   -- for a substitution variable of char data type 
end;           -- to be treated as a character string it needs
/              -- to be enclosed with single quotation marks

这篇关于如何在运行时从用户获取输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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