SQL*Plus 如何从提示中接受文本变量?
我是 psql 的初学者,我有一个问题.
Im very beginner in psql and i have a question.
代码如下:
SET serveroutput ON
ACCEPT myVariable PROMPT "Input value: ";
BEGIN
dbms_output.put_line('My input variable is: '||&myVariable);
END;
问题很简单:如何将文本传递给我的变量?如果我输入一个数字,它可以正常工作并且我可以在日志中读取我的数字,但是如果我传递像mytext"这样的文本而不是数字,我会收到一个错误:
Question is very simple: How can i pass text to my variable? If i input a number it is works correctly and i can read in the log my number, but if i pass a text like "mytext" instead of a number, i got an error:
old:BEGIN
dbms_output.put_line('My input variable is: '||&myVariable);
END;
new:BEGIN
dbms_output.put_line('My input variable is: '||mytext);
END;
Error starting at line 5 in command:
BEGIN
dbms_output.put_line('My input variable is: '||&myVariable);
END;
Error report:
ORA-06550: 2 sor, 50 oszlop:
PLS-00201: identifier 'MYTEXT' must be declared
ORA-06550: 2 sor, 3 oszlop:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:
%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
推荐答案
您必须指定数据类型作为 接受声明.如果没有给出,则假定一个数字.
You have to specify the data type as part of the ACCEPT statement. If none is given, it assumes a number.
尝试 ACCEPT myVariable CHAR PROMPT 'Input value: ';
代替.
相关文章