oracledb:如何将函数结果存储到过程中的变量中
你好。我有一个功能:oracledb:如何将函数结果存储到过程中的变量中,oracle,plsql,Oracle,Plsql,你好。我有一个功能: create function get_n(search tt.pp%type) return number is rc number; begin select count(*) into rc from tt where tt.pp=search; return (rc); end; / 我可以得到结果 variable qwe number; begin select get_n('sample') into :qwe
create function get_n(search tt.pp%type)
return number
is rc number;
begin
select count(*)
into rc
from tt
where tt.pp=search;
return (rc);
end;
/
我可以得到结果
variable qwe number;
begin
select get_n('sample')
into :qwe
from dual;
end;
print qwe;
所以,它成功地工作了。但按部分:在执行其他命令时,我无法执行带有打印的行(PLS-00103:遇到符号“打印”…)。这真的很奇怪
我尝试从匿名块中的函数获取结果并打印它:
declare
qwe number;
begin
select get_n('sample')
into :qwe
from dual;
dbms_output.put_line(qwe);
exception
when others
then dbms_output.put_line(sqlerrm);
end;
/
而且它没有打印任何东西。为什么?问题是:
。以下代码应该可以工作:
declare
qwe number;
begin
select get_n('sample')
into qwe
from dual;
dbms_output.put_line(qwe);
exception
when others
then dbms_output.put_line(sqlerrm);
end;
/
:
表示需要绑定的变量,而不是PL/SQL块中的变量
在第一个块的情况下,PL/SQL块之后缺少/
,是什么导致编译器将print
作为PL/SQL而不是SQLplus脚本的一部分读取:
variable qwe number;
begin
select get_n('sample')
into :qwe
from dual;
end;
/
print qwe;
是的,我只需要:=
函数的值,但是为什么这不起作用呢?使用更简单的qwe:=get\n('sample')
?@a\u horse\u和\u no\u name这一切都很好,只是想知道在这种情况下有什么问题