我不確定爲什麼我得到此代碼的錯誤,請幫助我在調試此代碼時提前致謝。使用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