【发布时间】:2014-11-14 14:24:23
【问题描述】:
在select SOMETHING into v_something 之前,我想知道我的查询是否返回一行。
这是一个很好的方法,但如果该行存在,则需要花费两个 select:
select count(1) into isRowExists from PERSON where CONDITION='Something';
if (isRowExists > 0) then
select NAME into v_name from PERSON where CONDITION='Something';
else
raise name_not_found;
end if;
select count(1) into isRowExists from CAR where CONDITION='Something';
if (isRowExists > 0) then
select MODEL into v_model from CAR where CONDITION='Something';
else
raise model_not_found;
end if;
或者类似的东西:
select NAME into v_name from PERSON where CONDITION='Something';
select MODEL into v_model from CAR where CONDITION='Something';
exception
when no_data_found then
--do_something
但是用这个方法,不知道问题是出自PERSON还是CAR...
还有其他解决方案吗?就像向exception 发送参数一样?
【问题讨论】:
-
当 no_data_found 与 2 个单独的异常块一起使用时
-
@6ton 你有例子吗?
-
为什么要在从行中检索值之前检查行是否存在?根据定义,如果您的查询未能返回一行,则该行不存在。