我有基本功能:
create or replace function t_owner(tname in varchar2, oname out varchar2)
return varchar2
is
begin
select owner into oname from table where table_name = 'tname';
return oname;
end;
select t_owner('table_test') from dual;
当我打电话给我时,我得到这个:
ORA-06553:PLS-306:调用“ T_OWNER”时参数的数量或类型错误
答案 0 :(得分:1)
函数不应具有OUT参数;他们会返回该值。所以:
create or replace function t_owner(tname in varchar2)
return varchar2
is
oname table.owner%type; --> declare a local variable which will be returned
begin
select owner into oname from table where table_name = tname;
return oname;
end;
如果要使用OUT
参数,请切换到以下过程:
create or replace procedure t_owner(tname in varchar2, oname out varchar2)
is
begin
select owner into oname from table where table_name = tname;
end;
您称其为
declare
l_out table.owner%type;
begin
t_owner('table_test', l_out);
dbms_output.put_line(l_out);
end;
答案 1 :(得分:1)
oname
应该是局部变量,而不是输出参数,tname
不应作为字符串而是输入参数被引用。
create or replace function t_owner(tname in varchar2)
return varchar2
is
oname table.owner%type;
begin
select owner into oname
from table
where table_name = tname;
return oname;
end;
select t_owner('table_test') from dual;
答案 2 :(得分:0)
函数是一个返回单个值的子程序,它仅隐式地返回一个out值,因此,无需将其定义为已使用return
关键字指出的参数。结果,您需要摆脱第二个参数并将其转换为局部变量:
create or replace function t_owner( tname mytable.table_name%type )
return mytable.owner%type
is
oname mytable.owner%type;
begin
select owner into oname from mytable where table_name = tname;
return oname;
end;
而且
tname
周围的引号,否则参数的存在将毫无意义。因为不会被使用。<table_name>.<column_name>%type
,以强调变量的定义,并避免相关表的数据类型或长度可能出现的可能性。table
替换为mytable
。