开发者

Is there a way to change the exception message in oracle?

开发者 https://www.devze.com 2023-04-11 07:17 出处:网络
I have 开发者_开发知识库a PHP application on top of an Oracle DB. In the database, there are some constraints defined. When they get violated, I get a plain constraint violated message. I would like t

I have 开发者_开发知识库a PHP application on top of an Oracle DB. In the database, there are some constraints defined. When they get violated, I get a plain constraint violated message. I would like to have some custom message shown to the user.

Is there a way to define in the definition of the constraint a custom error message ? Or how would you suggest me to approach this issue ?

Thanks!


Catch the exception and inform the user however you feel is appropriate.

php: catch exception and continue execution, is it possible?


Ask yourself why your invalid data is reaching your database?

You should implement strong validation on your inputs to prevent this happening as the constraints are only there as a last resort, not a front line for validating data.

Create validation routines that trap and report back (with a useful message) invalid data only sending valid data to be inserted into your database.

This could be done using PL/SQL stored procedures/packages/functions, a good article on using them for CRUD operations is here: http://www.devshed.com/c/a/Oracle/Developing-Simple-PL-SQL-Stored-Procedures-for-CRUD-Operations/

Or you could potentially use database triggers for this purpose, though "BEFORE" operation triggers are not as efficient as bulk processing collection data in a PL/SQL validation package.

Hope this helps...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号