【发布时间】:2020-02-05 09:48:13
【问题描述】:
我在使用游标更新记录时陷入无限循环。这是代码......我应该怎么做的任何建议?
CREATE OR REPLACE PROCEDURE SHADI.filling_conditional
as
cursor filling_cursor is select * from deposits_table for update;
begin
for i in filling_cursor
loop
update deposits_table
set conditional_flag = case
when i.deposit_amount > 1000 and i.currency_code = 'JOD'
and (select customer_info.sex
from customer_info
where customer_info.customer_number = i.customer_number) = 1
then 1
else 0
end;
end loop;
end filling_conditional;
/
【问题讨论】:
-
不需要光标。
-
如果你真的想用最慢的方式来更新一个表,你至少应该在你的
update语句中使用where current of。目前,游标的每次迭代都会更新表中的 all 行 - 我很确定这不是你想要的。 -
我是 oracle 新手,我需要将这个过程作为游标来实现。有任何想法吗?感谢您的回复。
-
这是一种奇怪的“做法”,教的东西效率低下。
-
@a_horse_with_no_name 感谢您的回复,我是 Oracle 的新手。主要思想是迭代 deposit_table 中符合上述条件的每一行。并相应地更新它们
标签: sql oracle sql-update database-cursor