清理重复姓名多个主键的I的存储过程 update 不成功
create or replace
PROCEDURE update_new(param in varchar2) IS
CURSOR cur1 IS SELECT l.id from leaguer l where l.imei =param order by l.id desc;
curid number :=0;
idx number := 1;
maxId number;
msg varchar2(200);
BEGIN
BEGIN
OPEN cur1;
LOOP
FETCH cur1 INTO curid;
EXIT WHEN cur1%NOTFOUND;
dbms_output.put_line(curid);
if idx = 1 then
maxId := curid;
idx :=2;
else
msg := to_char(maxId);
msg := msg || '-';
msg := msg || to_char(curid);
update PRODUCT_CLICK qb set qb.leaguer_id = maxId where qb.leaguer_id = curid;
if sql%rowcount >0 then
msg := msg ||' PRODUCT_CLICK ' ||to_char(sql%rowcount);
end if;
dbms_output.put_line(msg);
msg := null;
commit;
end if;
END LOOP;
CLOSE cur1;
END;
END update_new ;
CREATE OR REPLACE PROCEDURE loopImei IS
CURSOR cur1 IS SELECT imei from leaguer group by imei having count(imei)>1;
imei varchar(200);
BEGIN
BEGIN
OPEN cur1;
LOOP
FETCH cur1 INTO imei;
EXIT WHEN cur1%NOTFOUND;
if not imei is null then
-- dbms_output.put_line(imei);
update_new(imei);
end if;
END LOOP;
CLOSE cur1;
END;
END loopImei;
过程遇到的问题:
1、update不成功,因为我一开始curid的声明为id,而在leaguer表中就有id字段,变为curid即可。
总是遗漏end if;导致报错。
异常处理,写上后报错。未找到原因。