急!!新手请教:--ORA-01403: no data found 解决方法??

[复制链接]
查看11 | 回复9 | 2011-11-1 16:23:26 | 显示全部楼层 |阅读模式
请问:在执行以下语句时报错。
declare
v_spec varchar2(255);
begin
for r in (select subne.id, subne.subneassetid from subne where subne.subneassetid >0)
loop

select subnetype.subnemodel into v_spec from subnetype , subne

wheresubne.id = r.id and subne.subnetypeid = subnetype.id;

update asset set specformula = v_spec where id = r.subneassetid and specformula is null;
end loop;
end;
ORA-01403: 未找到数据
ORA-06512: 在line 6
我在网上查有人提议添加异常处理,可是那样loop里其它就不能被执行到了呀,请问各位高手该怎么解决呢??thx
回复

使用道具 举报

千问 | 2011-11-1 16:23:26 | 显示全部楼层
循环里面加异常处理
exception
when others then
null;
回复

使用道具 举报

千问 | 2011-11-1 16:23:26 | 显示全部楼层
建议把里面的INTO的SQL也写成游标,这样就不会有这种问题了.
回复

使用道具 举报

千问 | 2011-11-1 16:23:26 | 显示全部楼层
问题出在select subnetype.subnemodel into v_spec from subnetype , subne
where subne.id = r.id and subne.subnetypeid = subnetype.id;
没有数据选出,导致into出错.
回复

使用道具 举报

千问 | 2011-11-1 16:23:26 | 显示全部楼层
加个独立的块,
begin
select subnetype.subnemodel into v_spec from subnetype , subne
where subne.id = r.id and subne.subnetypeid = subnetype.id;
update asset set specformula = v_spec where id = r.subneassetid and specformula is null;
exception
when other then
null;
end;
这样在no_data_found时,就不会跳出了!
回复

使用道具 举报

千问 | 2011-11-1 16:23:26 | 显示全部楼层
asiaidea :
建议把里面的INTO的SQL也写成游标,这样就不会有这种问题了.
可以具体说一下吗?thx!!
回复

使用道具 举报

千问 | 2011-11-1 16:23:26 | 显示全部楼层
tohanjs:
我这里只有一个select ...into 语句,用exception独立快进行处理是可以的,如果还有其它的select ...into语句,是不是就不会被执行了呢?那样应该就不对了吧。
回复

使用道具 举报

千问 | 2011-11-1 16:23:26 | 显示全部楼层
declare
v_spec varchar2(255);
begin
for r in (select subne.id, subne.subneassetid from subne where subne.subneassetid >0)
loop
begin
select subnetype.subnemodel into v_spec from subnetype , subne
where subne.id = r.id and subne.subnetypeid = subnetype.id;
execpiton when others then
dbms_output.put_line('无数据');
end;
update asset set specformula = v_spec where id = r.subneassetid and specformula is null;
end loop;
end;
回复

使用道具 举报

千问 | 2011-11-1 16:23:26 | 显示全部楼层
SELECT ........INTO .............语句和游标性质是一样的.而游标如果没有结果是不会报错的.
declare
v_spec varchar2(255);
cursor ss is
select subnetype.subnemodelfrom subnetype , subne
where subne.id = r.id and subne.subnetypeid = subnetype.id;
begin
for r in (select subne.id, subne.subneassetid from subne where subne.subneassetid >0)
loop
for i inss loop
if ss%found and ss%rowcount = 1 then
v_spec:= i.subnemodel;
else
v_spec := null;
end if;
end loop;
if v_spec is not null then
update asset set specformula = v_spec where id = r.subneassetid and specformula is null;
end if;
end loop;
end;
回复

使用道具 举报

千问 | 2011-11-1 16:23:26 | 显示全部楼层
最初由 bigsea1017 发布
[B]tohanjs:
我这里只有一个select ...into 语句,用exception独立快进行处理是可以的,如果还有其它的select ...into语句,是不是就不会被执行了呢?那样应该就不对了吧。 [/B]

不会影响的,有异常就不处理update了,没有就执行update!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行