ScrappyDev
ScrappyDev

Reputation: 2778

How would you retrieve specific error codes from an oracle database programmatically?

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;
/

Upvotes: 1

Views: 207

Answers (1)

Kirill Leontev
Kirill Leontev

Reputation: 10941

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');

Upvotes: 1

Related Questions