如何读取用户写入的输入值?在 PL/SQL

How can I read input values ​written by a user? In PL/SQL

DECLARE
  text VARCHAR2(20) := &text;
BEGIN
  DBMS_OUTPUT.PUT_LINE(text);
END;

当我声明这个匿名块以便用户通过键盘输入值时,它在控制台输出中显示错误。

这是错误:

Error starting at line: 3 of the command:
 DECLARE
  text VARCHAR2(20) := Hello;
 START
  DBMS_OUTPUT.PUT_LINE(text);
  END;
Bug report -
ORA-06550: line 2, column 26:
PLS-00201: identifier 'HELLO' must be declared
ORA-06550: line 2, column 10:
PL/SQL: Item ignored
ORA-06550: line 4, column 25:
PLS-00320: The type declaration of this expression is incomplete or has a wrong format.
incorrect
ORA-06550: line 4, column 4:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:

在此块中,您试图将另一个变量 Hello(不是它的值)传递给 text 变量。 使用撇号使编译器将其解释为值而不是变量 - 'Hello'

DECLARE
  text VARCHAR2(20) := Hello; --<< change to 'Hello'
 START
  DBMS_OUTPUT.PUT_LINE(text);
 END;

因为这是一个替换变量,其数据类型为 varchar2,请将其括在单引号中(与任何其他字符串一样):

SQL> declare
  2    text varchar2(20) := '&text';            --> this
  3  begin
  4    dbms_output.put_line(text);
  5  end;
  6  /
Enter value for text: Hello
old   2:   text varchar2(20) := '&text';
new   2:   text varchar2(20) := 'Hello';
Hello

PL/SQL procedure successfully completed.

SQL>