为什么以下代码无法使用以下错误进行编译。我尝试使用不同的输入a
,1
和NULL
每次运行该块三次。
Name Null Type
------- ---- ------------
col_nam VARCHAR2(20)
编译日志:
Error: PLS-00049: bad bind variable 'x'
代码:
create or replace function ret_bool return boolean is
num_var number;
begin
select col_nam into num_var from ex04011601 where col_nam=:x; //statement 1
return true;
end;
/
答案 0 :(得分:0)
您需要将X作为参数传递给您的函数:
create or replace function ret_bool( X IN VARCHAR2)
return boolean is
num_var number;
begin
select col_nam into num_var from ex04011601 where col_nam= X;
return true;
end;
答案 1 :(得分:0)
因为在这种情况下,主机变量不能在PL / SQL过程的定义中的任何地方引用。
....对于SQL语句或PL / SQL块中的每个占位符,您必须 调用一个OCI例程来绑定你的变量的地址 程序到占位符...
在编译期间,占位符没有变量(分配了内存),它的地址可以绑定。
答案 2 :(得分:0)
“我猜即使在程序规范
procedure proc(:n1 in out number)...
使用绑定变量”
在某些时候,用户必须提供实际值。这是使用绑定变量的地方。
让我们使用你的函数并使用一个参数作为PL / SQL:
create or replace function ret_bool (p_arg in number)
return boolean is
num_var number;
begin
select col_nam into num_var
from ex04011601
where col_nam= p_arg;
return true;
end;
/
使用绑定变量的正确方法是调用函数:
EXEC SQL EXECUTE
BEGIN
:x := ret_bool(:n);
...