我这里有问题。我有两张桌子pp_gabungan
和jharga
. Jharga
用于存储预算值,另一方面pp_gabungan
用于保存书籍采购数据。我需要使用光标自动更新表eks
上的字段。pp_gabungan
例如,只要包含 from 的总价格sum of (eks*harga)
小于budget
,则 eks 字段的值应加一。但问题是这段代码有效,但它只更新一次。只要sum(eks*harga)
小于 ,它就不应停止递增budget
。你们能帮我是否应该添加更多循环吗?如果是的话..应该怎么做?这是我的代码:
DECLARE
bb jharga.budget%type;
tharga jharga.budget%type;
CURSOR eksupdate IS
SELECT
isbn,judul,frekuensi,stok,harga,prioritas,eks,kelompok,bobot
FROM pp_gabungan
FOR UPDATE OF eks NOWAIT;
autoeks eksupdate%ROWTYPE;
BEGIN
OPEN eksupdate; -- rows are locked.
select budget into bb from jharga;
select sum(eks*harga) into tharga from pp_gabungan;
LOOP
FETCH eksupdate INTO autoeks;
--EXIT WHEN eksupdate%NOTFOUND;
tharga:=(autoeks.eks*autoeks.harga);
IF tharga <= bb THEN
UPDATE pp_gabungan
SET eks = autoeks.eks+1
WHERE CURRENT OF eksupdate ;
END IF;
exit when tharga > bb;
END LOOP;
--COMMIT; -- rows are unlocked.
CLOSE eksupdate;
end;