0

嗨,伙计们,我正在尝试更新一些这样的行:

declare
   cursor c1 is select core_cust_id, ADDRESS_LINE1, ADDRESS_LINE2, ADDRESS_LINE3,CITY_CODE,
   STATE_CODE from crmuser.address where corp_id is not null and 
ADDRESSCATEGORY='Mailing';
   begin
   for i in c1 loop
   update  crmuser.tradefinance set ADDR_1=i.ADDRESS_LINE1,
   ADDR_2=i.ADDRESS_LINE2, ADDR_3=i.ADDRESS_LINE3, CITY_CODE=i.CITY_CODE,
   STATE_CODE=i.STATE_CODE       
   where i.core_cust_id=(select core_cust_id from crmuser.tradefinance where corp_id is not null);
   end loop; 
   end;

我收到错误:

ORA-01427: single-row subquery returns more than one row
ORA-06512: at line 7

当我执行

select core_cust_id, ADDRESS_LINE1, ADDRESS_LINE2, ADDRESS_LINE3,CITY_CODE,
   STATE_CODE from crmuser.address where corp_id is not null and 
ADDRESSCATEGORY='Mailing';

我得到了 485 条记录,我想用它们来匹配 Core_cust_id。当我执行时:

select core_cust_id from crmuser.tradefinance where corp_id is not null;

我再次获得 485 core_cust Id 以匹配循环中的其他 Core_cust_ids...为什么我的查询返回多个记录?我应该纠正什么?我正在使用 Oracle 10g

4

1 回答 1

1

尝试这个

declare
   cursor c1 is select core_cust_id, ADDRESS_LINE1, ADDRESS_LINE2, ADDRESS_LINE3,CITY_CODE,
   STATE_CODE from crmuser.address where corp_id is not null and 
ADDRESSCATEGORY='Mailing';
   begin
   for i in c1 loop
   update  crmuser.tradefinance set ADDR_1=i.ADDRESS_LINE1,
   ADDR_2=i.ADDRESS_LINE2, ADDR_3=i.ADDRESS_LINE3, CITY_CODE=i.CITY_CODE,
   STATE_CODE=i.STATE_CODE       
   where i.core_cust_id=crmuser.tradefinance.core_cust_id 
   and crmuser.corp_id is not null;
   end loop; 
   end;
于 2012-10-10T12:25:24.390 回答