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 ((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
)
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
Well, your code does this:
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?
If so, all you need to do is add an exception block to handle the error. Perhaps:
The documentation covers handling PL/SQL exceptions in depth.