当你将查出来的值,into给一个定义的变量的时候,首先判断是否查询出来值。
create or replace procedure procedureName(
parameterName in parameterType
parameterName out parameterType
)
as
testStr varchar2(30);
checkNum ineger;
begin
select t.col1 into testStr from tableA t where t.testVar = condition_str;
/*
当你在执行上面的sql时,可能会出现三种情况:
1. 没有查询出数据,into给testStr 会报 ORA-01403
2. 查询出多条数据,into给testStr 也会报异常(具体什么忘记了)
3. 查询出一条数据,是正确的
改正,如下:
*/
在执行上面语句前,请添加一句:
select count(*) into checkNum from tableA t where t.testVar = condition_str;
if checkNum =0 --查询不存在情况
then
---分别处理
elsif checkNum >1 --查询大于1情况
then
--分别处理
end if;
end;