0

I am writing procedure where i am passing input values. I need to validate against the metadata, if not valid raise exception.using oracle exception i have validated condition then raised the exception. I have copied the code i have used for validation.

IF V_BUSN_APPLC_NM_COUNT = 0 THEN
        RAISE INVALID_SYSTEM_IDENTIFER;
    END IF;

    IF V_PROCES_TYPE_COUNT = 0 THEN
        RAISE INVALID_PROCES_TYPE;
    END IF;

as per my logic it should display both the values but displaying me only one message. how to display both the messages.

Does both IF's will execute? if so why it is not printing the both values.

in java we have take error as an array, then add to array and display list of array elements. do we have any thing like this in oracle.

4

2 回答 2

1

如果你想把它保存在一个数组中,你可以这样做:

/* package with exceptions */
CREATE OR REPLACE PACKAGE exception_pkg AS
    composite_exception EXCEPTION;
END exception_pkg;

/* procedure */
DECLARE
    TYPE errors_ntt IS TABLE OF VARCHAR2(100);
    l_errors  errors_ntt := errors_ntt();
BEGIN
    DECLARE
        /* set variables to get errors */
        V_BUSN_APPLC_NM_COUNT NUMBER := 0;
        V_PROCES_TYPE_COUNT   NUMBER := 0;
    BEGIN
        IF V_BUSN_APPLC_NM_COUNT = 0 THEN
            /* add error to array */
            l_errors.EXTEND;
            l_errors(l_errors.LAST) := 'INVALID_SYSTEM_IDENTIFER';
        END IF;

        IF V_PROCES_TYPE_COUNT = 0 THEN
            l_errors.EXTEND;
            l_errors(l_errors.LAST) := 'INVALID_PROCES_TYPE';
        END IF;

        IF l_errors.COUNT > 0 THEN
            RAISE exception_pkg.composite_exception;
        END IF;
    END;
EXCEPTION
    WHEN exception_pkg.composite_exception THEN
        FOR indx IN 1..l_errors.COUNT LOOP
            /* print results */
            DBMS_OUTPUT.PUT_LINE(l_errors(indx));
        END LOOP;
        RAISE;
END;
/*
INVALID_SYSTEM_IDENTIFER
INVALID_PROCES_TYPE
*/
于 2013-06-24T08:38:07.767 回答
0

异常的第一次引发会结束过程的执行,因此不会执行进一步的代码。

如果需要显示所有值,则必须使用带有 OUT 参数的过程(无异常),或者在错误消息中使用两个值引发一个异常。

于 2013-06-24T06:36:46.633 回答