没有光标处理的行数

时间:2015-02-04 10:59:38

标签: oracle

declare
cid number;
cadd number;
ctras number;
pr varchar(2);
vad number;
cursor c1 IS
select ac_tras, cust_id, cust_addr from customer_master;
cursor c2 IS
select pr_adr from customer_address where cust_id = cid and cust_addr = cadd;
BEGIN
open c1;
LOOP
fetch c1 into ctras, cid, cadd;
EXIT WHEN C1%NOTFOUND;
OPEN c2;
LOOP
fetch c2 into pr;
if pr='Y'
THEN EXIT ;
ELSE
UPDATE customer_master 
set cust_addr = (select cust_addr from customer_address where pr_adr = 'Y' and cust_id = cid) where ac_tras = ctras;
END IF;
EXIT WHEN C2%NOTFOUND;
END LOOP;
Close C2;
END LOOP;
CLOSE C1;
END;

您好。在上面的代码中,我需要找到所获取的行数。如何找到它。换句话说,我必须找到处理了多少行或为Cursor C1迭代循环的次数

1 个答案:

答案 0 :(得分:0)

您可以使用SQL%ROWCOUNT来回显更新的行数 示例(将您的代码解释为相关部分,同时为理智添加COMMIT):

...
UPDATE customer_master
SET cust_addr =
  (SELECT cust_addr FROM customer_address WHERE pr_adr = 'Y' AND cust_id = cid
  )
WHERE ac_tras = ctras;
DBMS_OUTPUT.PUT_LINE('Updated ' || SQL%ROWCOUNT || ' records.');
...

Source