请教关于oracle中写存储过程时 select into 语句报错的问题

2025-03-24 12:00:22
推荐回答(4个)
回答1:

定义一个块,块中说明异常情况下如何处理就可以了。
begin
select 字段 into 变量...
exception
when NO_DATA_FOUND then --未找到时
处理逻辑
when exception_code then --这里的错误代码可以在standard包中找到
处理逻辑
when OTHERS then --default错误时
处理逻辑
end;
错误代码可通过如下语句获得:
select * from dba_source where owner='SYS' and name='STANDARD' and type='PACKAGE' and text like ' pragma EXCEPTION%';

回答2:

最简单的语句:就是在你的字段加上max函数。如
select max(id)into var_id from tab where id=某一个值
呵呵,谁用谁明白。

回答3:

exception
when no_data_found then
--你的处理逻辑

回答4:

exception
when no_data_found then
null;