完全一样,没有任何维护。但有几种方法可以伪造它:
如果您只需要做一件事,那么在隐式游标内部执行该操作即可确认您的值是否存在。
for i in (some_query) loop
do_something;
end loop;
您还可以在这里设置一个值,并在if
for i in (some_query) loop
result := True;
end loop;
if result then
do_something;
else
do_something_else;
end if;
使用它,或者你可以使用显式游标,赶上no_data_found
错误会引发
declare
cursor c_blah is
select my_value
from my_table
where id = my_id
;
my_value varchar2(4000);
begin
open c_blah(my_id);
fetch c_blah into my_value;
close c_blah;
do_something;
exception when no_data_found then
do_something_else;
end;
来源
2012-02-15 21:40:24
Ben
解释有关rownum = 1的部分?这是否会提高查询的速度,否则可能会计数一百万行?或者它只是获得1或0的布尔值的一个好方法? – Buttons840 2012-02-16 17:42:08
@ Buttons840正确。如果您正在搜索非关键字段的存在,那么在找到满足where子句的第一条记录时关闭该查询。代码逻辑正在检查0的情况,所以不使用实际的计数。 – tawman 2012-02-16 20:57:33
@ Buttons840正是!我的答案从左至右进行评估。你的OR的第一部分是正确的;) – tawman 2012-02-16 21:10:49