我有两张桌子。
Customer_Master
有3列c_id
,c_addr
,c_trans
Customer_Address
有3列c_id
,c_addr
,pr
我将Customer_Master
提取到Cursor C1
并将Customer_address
提取到Cursor C2
中。光标中的Select语句C2
具有Where
条件,该条件来自从光标C1获取的列c_id
和c_addr
。
Cursor C1
Select Statement:
Select c_trans, c_id, c_addr, from customer_master
c_trans
是主键。不是空的和独特的
光标C2
选择参数:
Select pr from customer_address where c_id = cid and c_addr = cad
pr
仅包含值True或False。
现在,我必须检查以查看天气pr
包含值'True'。如果是真的,就不必做任何事情。
如果为false,则必须更新c_addr
customer_master
customer_address . c_addr
,其值pr
为`Update customer_master
Set c_addr = (select c_addr from customer_address where pr = 'TRUE' and c_id = cid)
where c_trans = ctrans`
为真
`declare
cid number;
cadd number;
ctras number;
cr varchar(2);
cad number;
cursor c1 IS
select c_tras, c_id, c_add from customer_master;
cursor c2 IS
select c_address, cr from customer_address where c_id = cid;
begin
open c1;
open c2;
LOOP
fetch c1 into ctras, cid, cadd;
fetch c2 into cad, cr;
if cr='N'
THEN
update customer_master set c_address = (select c_address from customer_address where cr = 'Y' and c_id = cid) where c_tras = ctras;
END IF;
END LOOP;
END;`
如何实现这一点。
编辑:
我的代码;
{{1}}
答案 0 :(得分:0)
这很完美。
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;