这个问题,看你要如何处理。一个是事先检测是否有数据。例如select count(*) from .. where 条件。 如果有就查找 Into 进入。 还有一个是。使用exception. exception when no_data_found then dbms_output.put_line('没有数据!'); when others then dbms_output.put_line(sqlerrm);
如果是number型,可以利用变相的方法来实现。比如 select sum(nvl(SD_CWAZF,0)) into azfze from GC_ZCMX_SD where SD_BH=xmbh
如 上面说得 exception when no_data_found then return false;
select nvl((select nvl(SD_CWAZF,0) from GC_ZCMX_SD where SD_BH=xmbh),null) into azfze from dual ; 搞定,试过很多次了
其实 在存储里面使用 select into 时,如果没有得到数据时会触发 异常错误。 想控制这一点 只要用 begin select no,name into value1,value2 from emp; exception when others then ........ end;将 select into 给括上就可以了。还有就是可以考虑用cursor ,用cursor%notfound可以处理。
参考下 BEGIN SELECT OP_USERID INTO chrOpUserID FROM HU_REMOTE WHERE OP_ID = inChrOP_ID; EXCEPTION WHEN OTHERS THEN RAISE UPDATETWO_ERROR_EXCEPTION; END;
select count(SD_CWAZF) into count_azfze from GC_ZCMX_SD where SD_BH=xmbh ; if count_azfze >0 then select nvl(SD_CWAZF,0) into azfze from GC_ZCMX_SD where SD_BH=xmbh ; else azfze := 0; End if;
其实 在存储里面使用 select into 时,如果没有得到数据时会触发 异常错误。 想控制这一点 只要用 begin select nvl(SD_CWAZF,0) into azfze from GC_ZCMX_SD where SD_BH=xmbh; exception when others then ........ end;将 select into 给括上就可以了。
还有一个是。使用exception.
exception
when no_data_found then
dbms_output.put_line('没有数据!');
when others then
dbms_output.put_line(sqlerrm);
select sum(nvl(SD_CWAZF,0)) into azfze from GC_ZCMX_SD where SD_BH=xmbh
exception
when no_data_found then
return false;
想控制这一点 只要用
begin
select no,name into value1,value2 from emp;
exception
when others then
........
end;将 select into 给括上就可以了。还有就是可以考虑用cursor ,用cursor%notfound可以处理。
BEGIN
SELECT OP_USERID
INTO chrOpUserID
FROM HU_REMOTE
WHERE OP_ID = inChrOP_ID; EXCEPTION
WHEN OTHERS THEN
RAISE UPDATETWO_ERROR_EXCEPTION;
END;
from GC_ZCMX_SD where SD_BH=xmbh ;
if count_azfze >0 then
select nvl(SD_CWAZF,0) into azfze
from GC_ZCMX_SD where SD_BH=xmbh ;
else
azfze := 0;
End if;
想控制这一点 只要用
begin
select nvl(SD_CWAZF,0) into azfze from GC_ZCMX_SD where SD_BH=xmbh;
exception
when others then
........
end;将 select into 给括上就可以了。