处理并行查询服务器返回的异常

时间:2013-09-09 14:56:54

标签: exception plsql parallel-processing oracle11g

当并行查询服务器返回错误时,我很难弄清楚如何处理PL / SQL中的异常。

请考虑以下事项:

BEGIN                   

    EXECUTE IMMEDIATE('ALTER <SOME_INDEX> REBUILD PARALLEL(4) );

EXCEPTION

    WHEN OTHERS THEN

    IF SQLCODE = -01652 THEN

        DBMS_OUTPUT.PUT_LINE('Not enought space');

    ELSE

        DBMS_OUTPUT.PUT_LINE('[SQLCODE] -> '||SQLERRM);
        NULL;

    END IF;

END;

我正在尝试处理ORA-01652以通知表空间已满。

这里的问题是我没有抓到:

ORA-01652 unable to extend temp segment by 128 in tablespace <TBS>

而是:

ORA-12801: error signaled in parallel query server P001

因此ORA-01652未存储在SQLCODE中。我怎么能在这里处理真正的例外?

非常感谢。

2 个答案:

答案 0 :(得分:2)

捕获错误(极少数情况下需要WHEN OTHERS)并使用DBMS_Utility.Format_Error_Stack读取基础错误。

http://docs.oracle.com/cd/B28359_01/appdev.111/b28419/d_util.htm#sthref9680

答案 1 :(得分:1)

好吧,使用David Aldridge的建议解决了问题。如果某人有类似的问题,这是我提出的解决方案,使用INSTR功能:

BEGIN                   

    EXECUTE IMMEDIATE('ALTER <SOME_INDEX> REBUILD PARALLEL (DEGREE 4));

EXCEPTION

    WHEN OTHERS THEN

        -- If the error_stack contains the error code, then the error obviously occured
        -- INSTR will return the position of the string we are looking for
        -- otherwise, it will just return 0, hence the search condition :

        IF INSTR(DBMS_UTILITY.FORMAT_ERROR_STACK,'ORA-01658') > 0 THEN

            DBMS_OUTPUT.PUT_LINE('Tablespace full, too bad!');

        ELSE

            DBMS_OUTPUT.PUT_LINE('ERROR : '||DBMS_UTILITY.FORMAT_ERROR_STACK);

        END IF;

END;