对于项目,我需要根据同一属性的值修改表中的某些属性。我决定使用游标,并写下以下内容:
regex:/^\+1\(?([0-9]{3})\)-[0-9]{3}-[0-9]{4}$/
在这种情况下,DECLARE
totale_rente rekening.saldo%TYPE;
cursor c_boven1000 is
select r.reknummer,
r.saldo,
rt.rentepercentage,
ABS(ROUND(r.saldo * (rt.rentepercentage/100), 2 )) as teBetalen
FROM rekening r
join rekeningtype rt on rt.naam = r.rekeningtype
Where r.saldo < 0 and saldo >= -1000;
cursor c_onder1000 is
select r.reknummer,
r.saldo,
rt.rentepercentage,
ABS(ROUND(r.saldo * ((rt.rentepercentage*2)/100), 2 )) as teBetalen
From rekening r
join rekeningtype rt on rt.naam = r.rekeningtype
Where r.saldo < -1000;
TYPE rek_saldo IS TABLE OF rekening.saldo%TYPE;
TYPE rek_nummer IS TABLE OF rekening.reknummer%TYPE;
TYPE type_percentage IS TABLE OF rekeningtype.rentepercentage%TYPE;
TYPE rek_tebetalen IS TABLE OF rekening.saldo%TYPE;
rek_saldos rek_saldo;
rek_nummers rek_nummer;
type_percentages type_percentage;
rek_tebetalens rek_tebetalen;
BEGIN
OPEN c_boven1000;
FETCH c_boven1000 BULK COLLECT INTO rek_saldos, rek_nummers, type_percentages, rek_tebetalens;
CLOSE c_boven1000;
FOR x IN rek_nummers.first..rek_nummers.last LOOP
UPDATE rekening r
SET r.saldo = r.saldo - rek_tebetalens(x)
WHERE r.reknummer = rek_nummers(x);
totale_rente := totale_rente + rek_tebetalens(x);
END LOOP;
OPEN c_onder1000;
FETCH c_onder1000 BULK COLLECT INTO rek_saldos, rek_nummers, type_percentages, rek_tebetalens;
CLOSE c_onder1000;
FOR x IN rek_nummers.first..rek_nummers.last LOOP
UPDATE rekening r
SET r.saldo = r.saldo - rek_tebetalens(x)
WHERE r.reknummer = rek_nummers(x);
totale_rente := totale_rente + rek_tebetalens(x);
END LOOP;
UPDATE rekening r
SET saldo = saldo + totale_rente
WHERE r.reknummer = '2250';
END;
是Varchar,reknummer
是数字(10,2),saldo
是数字(3,2)。
执行时,我收到以下错误:
ORA-01722:执行PL / SQL代码的编号无效。
不确定它是否重要,但此代码块在单击按钮时处于动态操作中。 我试图找到我的错误,但一直无法。 有人可以帮忙吗?
答案 0 :(得分:2)
您选择列的顺序和变量的顺序不一样。
select r.reknummer
,r.saldo
,rt.rentepercentage
into rek_saldos
,rek_nummers
,type_percentages
您可以在游标中使用case语句:
select r.reknummer
,r.saldo
,rt.rentepercentage
,case
when saldo >= -1000 then
abs(round(r.saldo * (rt.rentepercentage / 100), 2))
else
abs(round(r.saldo * ((rt.rentepercentage * 2) / 100), 2))
end as tebetalen
from rekening r
join rekeningtype rt
on rt.naam = r.rekeningtype
where r.saldo < 0