我有程序SET_SUCCESSOR_KPI_STATUS
,当我尝试运行此程序时,我将获得Exception NO_DATA_FOUND in SET_SUCCESSOR_KPI_STATUS KPI_DEF_ID: 1000206
的异常。由于这个例外,整个流程都被破坏了。过程SET_SUCCESSOR_KPI_STATUS
正由另一个过程调用,如果此过程抛出异常,则其他过程正在生成问题。我不确定是否有任何方法可以捕获此异常。尝试使用KPI_DEF_ID
进行调用时,此过程可能会返回值,或者它可能包含null,因为没有找到数据,我正在收到错误。如果我从此过程中删除异常处理并运行它然后在其他一些过程中显示错误,但主要原因是在此过程中。
PROCEDURE SET_SUCCESSOR_KPI_STATUS
-- PUBLIC
(
IN_KPI_DEF_ID IN NUMBER DEFAULT 0
, IN_KPI_STATUS IN CHAR DEFAULT 'N'
, RET OUT Number
) IS
EV Number := 0;
SUCC Number := 0;
PARENTS_GREEN Number := 1;
SUCC_KPI_ACTIVE_INITIAL CHAR;
SUCC_KPI_ACTIVE_CURRENT CHAR;
BEGIN
SELECT KD.EVENT_ID INTO EV FROM RATOR_MONITORING_CONFIGURATION.KPI_DEFINITION KD WHERE KD.KPI_DEF_ID = IN_KPI_DEF_ID;
BEGIN
SELECT E.EVENT_SUCCESSOR_ID INTO SUCC FROM RATOR_MONITORING_CONFIGURATION.EVENT_SUCCESSOR E JOIN RATOR_MONITORING_CONFIGURATION.EVENT IN_EVENT ON E.EVENT_ID = IN_EVENT.EVENT_ID WHERE E.EVENT_ID = EV;
EXCEPTION WHEN NO_DATA_FOUND THEN
SUCC := 0;
END;
WHILE SUCC > 0
LOOP
SELECT KPI_ACTIVE_CURRENT INTO SUCC_KPI_ACTIVE_CURRENT from RATOR_MONITORING_CONFIGURATION.KPI_DEFINITION KD WHERE KD.EVENT_ID = SUCC;
SELECT KPI_ACTIVE_INITIAL INTO SUCC_KPI_ACTIVE_INITIAL from RATOR_MONITORING_CONFIGURATION.KPI_DEFINITION KD WHERE KD.EVENT_ID = SUCC;
UPDATE RATOR_MONITORING_CONFIGURATION.KPI_DEFINITION KD
SET KD.KPI_ACTIVE_CURRENT = CASE WHEN IN_KPI_STATUS = 'Y' AND (SELECT MONITORING.ARE_PARENTS_GREEN(KD.KPI_DEF_ID) FROM DUAL) = 1 AND SUCC_KPI_ACTIVE_CURRENT <> SUCC_KPI_ACTIVE_INITIAL THEN KD.KPI_ACTIVE_INITIAL WHEN IN_KPI_STATUS = 'N' AND (SUCC_KPI_ACTIVE_CURRENT <> SUCC_KPI_ACTIVE_INITIAL) THEN IN_KPI_STATUS ELSE KD.KPI_ACTIVE_CURRENT END,
KD.LAST_UPDATED_BY = 115,
KD.LAST_UPDATED_DATE = CURRENT_DATE
WHERE KD.EVENT_ID = SUCC;
BEGIN
SELECT E.EVENT_SUCCESSOR_ID INTO SUCC FROM RATOR_MONITORING_CONFIGURATION.EVENT_SUCCESSOR E JOIN RATOR_MONITORING_CONFIGURATION.EVENT IN_EVENT ON E.EVENT_ID = IN_EVENT.EVENT_ID WHERE E.EVENT_ID = SUCC;
EXCEPTION WHEN NO_DATA_FOUND THEN
SUCC := 0;
END;
END LOOP;
RET := 1;
EXCEPTION WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('Exception NO_DATA_FOUND in SET_SUCCESSOR_KPI_STATUS KPI_DEF_ID: '||TO_CHAR(IN_KPI_DEF_ID));
RET := 1;
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Exception OTHERS in SET_SUCCESSOR_KPI_STATUS KPI_DEF_ID: '||TO_CHAR(IN_KPI_DEF_ID));
RET := 0;
RAISE;
END SET_SUCCESSOR_KPI_STATUS;
答案 0 :(得分:2)
您的一些select into
语句已经很好地处理NO_DATA_FOUND
:
BEGIN
SELECT E.EVENT_SUCCESSOR_ID INTO SUCC FROM RATOR_MONITORING_CONFIGURATION.EVENT_SUCCESSOR E JOIN RATOR_MONITORING_CONFIGURATION.EVENT IN_EVENT ON E.EVENT_ID = IN_EVENT.EVENT_ID WHERE E.EVENT_ID = EV;
EXCEPTION WHEN NO_DATA_FOUND THEN
SUCC := 0;
END;
但其他人不是:
SELECT KPI_ACTIVE_CURRENT INTO SUCC_KPI_ACTIVE_CURRENT from RATOR_MONITORING_CONFIGURATION.KPI_DEFINITION KD WHERE KD.EVENT_ID = SUCC;
SELECT KPI_ACTIVE_INITIAL INTO SUCC_KPI_ACTIVE_INITIAL from RATOR_MONITORING_CONFIGURATION.KPI_DEFINITION KD WHERE KD.EVENT_ID = SUCC;
如果这些选择可以合法地不返回任何行,那么您也需要处理NO_DATA_FOUND
:
BEGIN
SELECT KPI_ACTIVE_CURRENT INTO SUCC_KPI_ACTIVE_CURRENT
from RATOR_MONITORING_CONFIGURATION.KPI_DEFINITION KD
WHERE KD.EVENT_ID = SUCC;
EXCEPTION
WHEN NO_DATA_FOUND THEN
-- Do what?
NULL;
END;
BEGIN
SELECT KPI_ACTIVE_INITIAL INTO SUCC_KPI_ACTIVE_INITIAL
from RATOR_MONITORING_CONFIGURATION.KPI_DEFINITION KD
WHERE KD.EVENT_ID = SUCC;
EXCEPTION
WHEN NO_DATA_FOUND THEN
-- Do what?
NULL;
END;
答案 1 :(得分:0)
如果没有可用数据,则值的分配将失败。而不是使用SELECT INTO语句考虑使用另一个游标并设置默认值。
您可能还想检查您正在使用的select语句。可能是联接表中的数据不存在,因此无法找到要返回的任何数据。
我希望这会被击落,但我会使用SUCC值作为参数来嵌套游标以获取此数据。
您还要为查询中的参数赋值。最好将值分配给另一个变量,并将其更新到查询之外。这样查询就不太可能使自己绊倒。