Oracle Error ORA-06512

后端 未结 3 743
你的背包
你的背包 2021-01-03 00:07

Just can\'t figure out why it gives me ORA-06512 Error

PROCEDURE PX(pNum INT,pIdM INT,pCv VARCHAR2,pSup FLOAT)
AS
    vSOME_EX EXCEPTION;

BEGIN 
    IF ((pN         


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-03 00:56

    ORA-06512 is part of the error stack. It gives us the line number where the exception occurred, but not the cause of the exception. That is usually indicated in the rest of the stack (which you have still not posted).

    In a comment you said

    "still, the error comes when pNum is not between 12 and 14; when pNum is between 12 and 14 it does not fail"

    Well, your code does this:

    IF ((pNum < 12) OR (pNum > 14)) THEN     
        RAISE vSOME_EX;
    

    That is, it raises an exception when pNum is not between 12 and 14. So does the rest of the error stack include this line?

    ORA-06510: PL/SQL: unhandled user-defined exception

    If so, all you need to do is add an exception block to handle the error. Perhaps:

    PROCEDURE PX(pNum INT,pIdM INT,pCv VARCHAR2,pSup FLOAT)
    AS
        vSOME_EX EXCEPTION;
    
    BEGIN 
        IF ((pNum < 12) OR (pNum > 14)) THEN     
            RAISE vSOME_EX;
        ELSE  
            EXECUTE IMMEDIATE  'INSERT INTO M'||pNum||'GR (CV, SUP, IDM'||pNum||') VALUES('||pCv||', '||pSup||', '||pIdM||')';
        END IF;
    exception
        when vsome_ex then
             raise_application_error(-20000
                                     , 'This is not a valid table:  M'||pNum||'GR');
    
    END PX;
    

    The documentation covers handling PL/SQL exceptions in depth.

    • Find out more.

提交回复
热议问题