首页 \ 问答 \ Oracle触发异常和回滚可能(Oracle trigger exception and rollback maybe)

Oracle触发异常和回滚可能(Oracle trigger exception and rollback maybe)

假设我有以下触发器:

create or replace trigger trigInsertSaloane before insert on saloane
for each row
declare
  myExcp exception;
  pragma exception_init (myExcp,-20005);
begin
  for i in (select * from saloane) loop
    if(:new.numar_salon=i.numar_salon) and (trim(upper(:new.nume_sectie))=trim(upper(i.nume_sectie))) then
    raise myExcp;
    end if;
  end loop;
  exception when myExcp then dbms_output.put_line('Record exists');
end;
/

我想要的只是在引发异常时不插入行,所以就像回滚一样。 在我的情况下,如果引发异常并捕获,则还会插入该行。 我不想要那个。 此外,我希望以一种漂亮的方式,通过显示一条消息而不会出现任何错误。如何制作它?


Suppose I have the following trigger :

create or replace trigger trigInsertSaloane before insert on saloane
for each row
declare
  myExcp exception;
  pragma exception_init (myExcp,-20005);
begin
  for i in (select * from saloane) loop
    if(:new.numar_salon=i.numar_salon) and (trim(upper(:new.nume_sectie))=trim(upper(i.nume_sectie))) then
    raise myExcp;
    end if;
  end loop;
  exception when myExcp then dbms_output.put_line('Record exists');
end;
/

All I want is to not insert the row if exception is raised, so something like rollback. In my case if exception is raised and caught, the line is also inserted. I don`t want that. Also I want to make that in a pretty way, by showing up a message and not getting any errors.How to make it?


原文:https://stackoverflow.com/questions/37004165
更新时间:2022-08-10 19:08

最满意答案

事实上, If Null不接受一个字段replace by value ,而只是一个值。

虽然其他解决方案也是可行的,但您可能需要使用Modify JavaScript Value 。 根据作业给变换的参数的方式,您可能需要通过if(load_date!='null')或者if(!load_date.isEmpty())来替换条件。

在这里输入图像描述


As a matter of facts the If Null does not accept a field in the replace by value, only a value.

Although other solutions are possible, you may want to use a Modify JavaScript Value. Depending on how the the parameter is given to your transformation by the job, you may have to replace the condition by if(load_date!='null') or if(!load_date.isEmpty()).

enter image description here

相关问答

更多