oracle 这个 PL/SQL 有什么问题?绑定变量 * 未声明
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1597806/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is wrong with this PL/SQL? Bind Variable * is NOT DECLARED
提问by NitroxDM
Here is:
这是:
declare
v_str1 varchar2(80);
begin
v_str1 := 'test';
print :v_str1;
end
When I run it using SQLDeveloper just in a sql worksheet I get this:
当我在 sql 工作表中使用 SQLDeveloper 运行它时,我得到了这个:
Bind Variable "v_str1" is NOT DECLARED
anonymous block completed
采纳答案by NitroxDM
Got it:
知道了:
set serveroutput on
declare
v_str1 varchar2(80);
begin
v_str1 := 'test';
dbms_output.put_line(v_str1);
end;
回答by EREN
print
is not a PLSQL function. If you want to get an output, you can use dbms_output.put_line(v_str1);
print
不是 PLSQL 函数。如果你想得到一个输出,你可以使用dbms_output.put_line(v_str1);
set serveroutput on;
declare v_str1 varchar2(80);
begin
v_str1 := 'test';
dbms_output.put_line(v_str1);
end;
:v_str1 is a bind variable but you must declare not in a plsql. When you declare it you must use VARIABLE keyword.
:v_str1 是一个绑定变量,但您不能在 plsql 中声明。当您声明它时,您必须使用 VARIABLE 关键字。
回答by FrustratedWithFormsDesigner
The bind variables syntax of the form :VARNAME are used primarily in SQL* Plus (except for bind variables for dynamic SQL, I think). For SQL* Developer, PL/SQL Developer, or other apps, there is the "&" for variable substitution:
:VARNAME 形式的绑定变量语法主要在 SQL* Plus 中使用(我认为动态 SQL 的绑定变量除外)。对于 SQL* Developer、PL/SQL Developer 或其他应用程序,变量替换有“&”:
declare
v_str1 varchar2(80);
begin
v_str1 := &v_str;
print v_str1;
end
EDIT:My bad, the code for Oracle SQL*Developer should have been:
编辑:我不好,Oracle SQL*Developer 的代码应该是:
set serveroutput on;
declare
v_str1 varchar2(80);
begin
v_str1 := '&v_str';
dbms_output.put_line(v_str1);
end;
You have to select everything and execute it. The result will appear in the "Script Output" panel.
您必须选择所有内容并执行它。结果将出现在“脚本输出”面板中。
回答by Aurelio Martin Massoni
Try
尝试
declare
v_str1 varchar2(80);
begin
v_str1 := 'test';
print v_str1;
end