简体   繁体   English

如何创建Oracle触发器并返回一些数据库错误代码,而不是自定义异常,而是实际的数据库错误?

[英]How to create and Oracle trigger to return some DB Error code, not the Custom Exception but real DB ERROR?

I would like to know is it possible to return a DB ERROR code from trigger, rather than Custom exception created with RAISE_APPLICATION_ERROR. 我想知道是否有可能从触发器返回DB ERROR代码,而不是使用RAISE_APPLICATION_ERROR创建的自定义异常。 I have some requirement where i need to return an DB ERROR code like 1 for Unique Constraint. 我有一些要求,我需要为唯一约束返回一个DB错误代码,例如1。 I have a purpose to ask this, because for some reason with some hash based partition we are not creating unique constraints on table and rather have one trigher with which i want to return Unique constraint as an error code after checking if the record exists in DB. 我有一个问题要问,因为出于某种原因,我们在基于哈希的分区上没有在表上创建唯一约束,而是希望在检查记录是否存在于数据库中之后,使用一个trigher来将唯一约束作为错误代码返回。 。

You can use: 您可以使用:

RAISE DUP_VAL_ON_INDEX;

Only in this case you can't pass any arguments to this error and you will get: 仅在这种情况下,您不能将任何参数传递给该错误,并且您将获得:

ORA-00001: unique constraint (.) violated ORA-00001:违反了唯一约束(。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM