set serveroutput on;
DECLARE
CURSOR
IS
SELECT SVL_ID
FROM SALES_VEHICLES
WHERE SVL_N = 'some value';--314653;
TYPE SVD_TA IS TABLE OF VSALES%ROWTYPE;
SV SVD_TA;
BEGIN
OPEN VSALES;
FETCH VSALES BULK COLLECT INTO SV LIMIT 1000;
CLOSE VSALES;
IF SV.COUNT() <> 0
THEN
FOR I IN 1..SV.COUNT()
LOOP
UPDATE SALES_VEHICLES
SET SVL_M = 'some value',
SVL_M = SVL_C_N
WHERE SVL_ID = I.SVL_ID;
COMMIT;
END LOOP;
END IF;
EXIT WHEN VSALES%NOTFOUND;
END LOOP;
CLOSE VSALES;
END;
我无法调试此问题。错误发生在第32行第5列。如果您能帮我解决这个问题,我将非常感激。
答案 0 :(得分:0)
你在第15行和第32行中双重关闭了相同的光标。
可能你不想在获取之后关闭。
BEGIN
OPEN VSALES;
LOOP
FETCH VSALES BULK COLLECT INTO SV LIMIT 1000;
IF SV.COUNT() <> 0
THEN
FOR I IN 1..SV.COUNT()
LOOP
UPDATE SALES_VEHICLES
SET SVL_M = 'some value',
SVL_M = SVL_C_N
WHERE SVL_ID = SV(I).SVL_ID;;
COMMIT;
END LOOP;
END IF;
EXIT WHEN VSALES%NOTFOUND;
END LOOP;
CLOSE VSALES;
END;
答案 1 :(得分:0)
我找到了解决方案。我错过了以下内容。这是我改变的内容
从此:
WHERE SVL_ID = I.SVL_ID;
对此:
WHERE SVL_ID = SV(I).SVL_ID;
答案 2 :(得分:0)
似乎比它需要的要复杂一点。对于普通的游标循环,您可以这样做:
begin
for r in (
select svl_id
from sales_vehicles
where svl_n = 'some value' --314653;
)
loop
update sales_vehicles
set svl_m = 'some value', svl_m = svl_c_n
where svl_id = r.svl_id;
end loop;
commit;
end;
或者如果你真的想要使用一个数组(并且有机会获得比你讨价还价更多的内存):
declare
type svid_tt is table of sales_vehicles.svl_id%type;
l_svids svid_tt;
begin
select svl_id bulk collect into l_svids
from sales_vehicles
where svl_n = 'some value';--314653;
if l_svids.count > 0 then
forall i in 1..l_svids.count
update sales_vehicles
set svl_m = 'some value', svl_m = svl_c_n
where svl_id = l_svids(i);
end if;
commit;
end;
您可以通过添加限制子句和循环以及检查批量异常等来使数组版本更加健壮。