我正在更新两张桌子(卡片)和(accountcomment)。
首先查询:
update card set cardstatusid = 3 where cardstatusid = 1 and card num in ('123', '456', '789');'
第二次查询:
Update accountcomment set text = 'CARDS EXPIRED' WHERE commentcategory = 10 and accountid in ('aaa', 'bbb', 'ccc');'
由于存在大量的卡片和帐号,我需要声明一个游标并使用PL / SQL语句。
所以我写了以下内容:
declare
cursor c1 is select personid from card where cardstatusid = 1 and card
num in ('123', '456', '789');
cursor c2 is select accountid from personaccount where personid in
(select personid from card where cardstatusid = 1 and card num in
('123', '456', '789'));
begin
for r1 in c1
loop
update card set cardstatusid = 3
where personid = r1.personid;
end loop;
for r2 in c2
insert into accountcomment
values ('CARDS EXPIRED', r2.accountid, 10);
end loop;
end;
它给了我一个错误.....我不确定我是否使用游标错误或某些声明......我不能在accountcomment中使用更新声明,因为commentcategory 10还没有退出那张桌子。
如果我可以使用一个很棒的光标。否则在修复当前的pl / sql时会有所帮助。
谢谢!
答案 0 :(得分:1)
card num不是有效的column_name(空格)。你也错过了一个"循环"。
这样的东西?
declare
cursor c1 is
select personid
from card
where cardstatusid = 1 and **cardnum** in ('123', '456', '789');
cursor c2 is
select accountid
from personaccount
where personid in (select personid
from card
where cardstatusid = 1 and **cardnum** in ('123', '456', '789'));
begin
for r1 in c1 loop
update card
set cardstatusid = 3
where personid = r1.personid;
end loop;
for r2 in c2 **loop**
insert into accountcomment
values ('CARDS EXPIRED', r2.accountid, 10);
end loop;
end;