我如何知道哪个SELECT
生成了NO_DATA_FOUND
?
示例:
CREATE [..]
DECLARE
--
BEGIN
SELECT [...]; -- will this
SELECT [...]; -- or this to generate NO_DATA_FOUND ?
EXEPCTION
WHEN NO_DATA_FOUND THEN
[...]
END;
答案 0 :(得分:4)
你可以这样做:
DECLARE
--
BEGIN
BEGIN
SELECT [...]; -- will this
EXCEPTION
WHEN NO_DATA_FOUND THEN
[...]
END;
BEGIN
SELECT [...]; -- or this to generate NO_DATA_FOUND ?
EXCEPTION
WHEN NO_DATA_FOUND THEN
[...]
END;
END;
或者:
DECLARE
l_where_am_i number;
BEGIN
l_where_am_i := 1;
SELECT [...]; -- will this
l_where_am_i := 2;
SELECT [...]; -- or this to generate NO_DATA_FOUND ?
EXEPCTION
WHEN NO_DATA_FOUND THEN
CASE l_where_am_i
WHEN 1 THEN [...]
WHEN 2 THEN [...]
END CASE;
END;
答案 1 :(得分:2)
另一种选择是使用dbms_utility.format_error_backtrace
,如下所示(尽管最好将该数据发送到错误记录例程)。此函数将为您提供发生错误的实际行号。
CREATE [..]
DECLARE
--
BEGIN
SELECT [...]; -- will this
SELECT [...]; -- or this to generate NO_DATA_FOUND ?
EXEPCTION
WHEN NO_DATA_FOUND THEN
[...]
dbms_output.put_line(dbms_utility.format_error_backtrace());
END;