1

Scenario:
I wish to define a constant for the DUP_VAL_ON_INDEX error code:

GCN_DUP_VAL_ON_INDEX        CONSTANT NUMBER := -1;

However, I would like to set the value programmatically:

GCN_DUP_VAL_ON_INDEX        CONSTANT NUMBER := DUP_VAL_ON_INDEX.ERRCODE;

Is there a way to do this w/out creating a custom function like this?:

CREATE OR REPLACE FUNCTION GET_DUP_VAL_ERR_CODE
RETURN INTEGER
IS
BEGIN
   raise dup_val_on_index;
EXCEPTION
   WHEN OTHERS THEN
      RETURN SQLCODE;
END;
/
4
  • 2
    what for? it's more common to do the very opposite things - define constant exceptions for error codes... Commented May 10, 2012 at 19:25
  • We are bulk collecting the erorrs during a forall loop, then doing logging for each exception. We use the error code to determine what to do next. Commented May 10, 2012 at 20:10
  • @scrappythenell, a forall will raise a single error for the entire data-set rather than a single record in that data-set. What happens if you want to do something else for only a single record? Is such a situation possible? Commented May 10, 2012 at 21:29
  • @Ben, it will not. Check out save exceptions clause ) Commented May 10, 2012 at 21:39

1 Answer 1

1

Probably not.

Check out SYS.STANDARD package - it's the place where all the exceptions, SQL functions, and everything else "predefined" is actually defined.

Pretty much straightforward:

DUP_VAL_ON_INDEX exception;
    pragma EXCEPTION_INIT(DUP_VAL_ON_INDEX, '-0001');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.