我已经有一个工作正常procedureA(int)
的存储过程。我需要将select语句中的行从procedureB
一个接一个地输入到procedureA中,如下所示:
create or replace procedure procedureB is
begin
for x in (
select CAST(n as int)
from table1)
loop
procedureA(x);
end loop;
end;
我在循环中遇到以下错误:
PLS-00306: wrong number or types of arguments in call to 'procedureA'
我使用CAST即使' n'是一个整数,因为我认为错误是因为我必须将选择结果作为int进行CAST。 (用于在使用CAST之前获得相同的错误)。
答案 0 :(得分:0)
该代码应该可以正常工作(假设procedureA可以处理传递整数)。通常,您不需要将列转换为整数,以便PLSQL循环它。这种类型的for循环基本上就像游标一样,并且在循环中为查询返回的每一行执行代码,而不管数据类型如何。
答案 1 :(得分:0)
假设procedureA接受int
作为参数,请尝试:
create or replace procedure procedureB is
begin
for x in (select CAST(n as int) as numb
from table1)
loop
procedureA(x.numb);
end loop;
end procedureB;
x
是一行,而不是int
,CAST(n as INT)
的结果未命名,直到您为其命名(此处我称之为numb
以区分它来自原始列名n
)。
分享并享受。