我不确定为什么我得到此代码的错误,请帮助我在调试此代码时提前致谢。使用BULK COLLECT将多个列分配给一个集合
declare
type emp_t is table of employees%rowtype
index by pls_integer;
rec emp_t;
begin
select employee_id,salary,manager_id bulk collect into rec
from employees where rownum <100;
forall i in 1..rec.last
update employees
set salary=salary+10
where employee_id=rec(i).employee_id;
end;
ORA-06550: line 7, column 3:
PL/SQL: ORA-00913: too many values
ORA-06550: line 6, column 3:
PL/SQL: SQL Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
我已经改变了代码以下格式,但它仍然给我“的表达是错误的类型的错误”
declare
type emp_t is table of employees%rowtype
index by pls_integer;
rec emp_t;
begin
for val in (
select employee_id,salary,manager_id
from employees where rownum <100)
loop
rec:=val;
end loop;
forall i in 1..rec.last
update employees
set salary=salary+10
where employee_id=rec(i).employee_id;
end;
即使在将代码更改为第二种形式之后,您能否解释它为什么会出现错误? – redsoxlost 2014-09-28 18:28:30
@Asfakul我没有尝试,但乍一看,这是同样的问题:你选择列的_subset_,但是'rec'仍然被声明为“全行”(使用%ROWTYPE)。简单地说:如果你使用'%ROWTYPE',你应该'SELECT *'。否则,您需要一个自定义记录类型。 – 2014-09-28 18:32:28
但是在游标的情况下,我可以声明一个rowtype变量,然后将列的子集提取到该变量中。我猜这是不允许在收集 – redsoxlost 2014-09-28 18:48:42