Oracle 错误 ORA-06512

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7815527/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 03:38:15  来源:igfitidea点击:

Oracle Error ORA-06512

oraclestored-proceduresplsqlora-06512

提问by Tililin Tin Tin

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

就是不明白为什么它给了我 ORA-06512 错误

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;
END PX;

The structure base for the table where the insert is made:

进行插入的表的结构基础:

CREATE TABLE "DB"."M12GR" (
    "IDM12GR" NUMBER(10,0) NOT NULL ENABLE, 
    "CV" VARCHAR(5) NOT NULL ENABLE, 
    "SUP" FLOAT(126) NOT NULL ENABLE, 
    "IDM12" NUMBER(10,0) NOT NULL ENABLE, 

    CONSTRAINT "PRIMARY_30" PRIMARY KEY ("IDM12GR"),
    CONSTRAINT "M12SUELORM12" FOREIGN KEY ("IDM12") REFERENCES "DB"."M12" ("IDM12") ENABLE
)

回答by APC

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).

ORA-06512 是错误堆栈的一部分。它给了我们发生异常的行号,但没有给出异常的原因。这通常在堆栈的其余部分(您尚未发布)中指示。

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"

“仍然,当 pNum 不在 12 和 14 之间时会出现错误;当 pNum 在 12 和 14 之间时,它不会失败”

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?

也就是说,当 pNum 不在 12 和 14 之间时,它会引发异常。那么错误堆栈的其余部分是否包括这一行?

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

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.

该文档深入介绍了处理 PL/SQL 异常。

回答by Ernesto Campohermoso

The variable pCv is of type VARCHAR2 so when you concat the insert you aren't putting it inside single quotes:

变量 pCv 是 VARCHAR2 类型,所以当你连接插入时,你不会把它放在单引号内:

 EXECUTE IMMEDIATE  'INSERT INTO M'||pNum||'GR (CV, SUP, IDM'||pNum||') VALUES('''||pCv||''', '||pSup||', '||pIdM||')';

Additionally the error ORA-06512 raise when you are trying to insert a value too large in a column. Check the definiton of the table M_pNum_GR and the parameters that you are sending. Just for clarify if you try to insert the value 100 on a NUMERIC(2) field the error will raise.

此外,当您尝试在列中插入过大的值时,会引发错误 ORA-06512。检查表 M_pNum_GR 的定义和您发送的参数。只是为了澄清,如果您尝试在 NUMERIC(2) 字段中插入值 100,则会引发错误。

回答by Ibrahim Danisg

I also had the same error. In my case reason was I have created a update trigger on a table and under that trigger I am again updating the same table. And when I have removed the update statement from the trigger my problem has been resolved.

我也有同样的错误。就我而言,原因是我在表上创建了一个更新触发器,在该触发器下我再次更新同一个表。当我从触发器中删除更新语句时,我的问题就解决了。