1

I rise DUP_VAL_ON_INDEX in SQL and I'd like to associate some custom error message with it. Right now after executing the code

IF ___SOME_CONDITION___ THEN
  RAISE DUP_VAL_ON_INDEX;
END IF

I see following message:

00001. 00000 -  "unique constraint (%s.%s) violated"

How I can provide custom message to substitute these "%s"?

Sergey
  • 376
  • 1
  • 2
  • 4

1 Answers1

3

You wouldn't typically raise these pre-defined errors yourself. Instead, you would either let the database raise them (eg. you really have tried to insert a row that violates the unique constraint/index) or raise your own custom error (eg. raise_application_error()) and provide the necessary information there.

Boneist
  • 22,910
  • 1
  • 25
  • 40
  • Oracle documentation says you may use these predefined exceptions and has an example. I don't think this is a valid answer. – Sergey Mar 04 '15 at 21:58
  • 1
    @Sergey This a valid answer - _"you wouldn't typically raise these pre-defined errors yourself"_. Instead define and raise your own `unique_constraint_violated` exception (see e.g. http://stackoverflow.com/q/6020450). (I'm not aware of any ways how to substitute the placeholders in the predefined exception texts.) – user272735 Mar 05 '15 at 05:18
  • @Sergey It's entirely possible to go jump off a cliff. That doesn't mean it's necessarily a good idea to do so! Yes, you can certainly raise the predefined errors as much as you like, but you have to bear in mind that Oracle has not provided a way for you to pass parameters into them. – Boneist Mar 05 '15 at 09:28
  • @Boneist _Oracle has not provided a way for you to pass parameters into them_. Thank you, this is what I've looked for. – Sergey Mar 05 '15 at 21:55