0

各行の後に INSERT トリガー イベントを持つ Oracle 10g トリガーがあり、挿入されている現在の行からトリガーのロジックを基にしたいと考えています。挿入されているユーザー テーブル フラグ列の値を取得し、トリガーで if-then-else を使用して、フラグが null の場合にのみ何かを実行したいと考えています。挿入される行のフラグ列の値を取得する方法についてのアイデアはありますか? 私の目標は、フラグ列の値が null の場合、以下のトリガーでロジックを実行しないことです。

Table: USERS

Columns:
id (PK generated from a DB sequence)
.... (more columns)
flag VARCHAR2(1 BYTE) and is nullable

引き金:

//goal is to not do any of the logic in the trigger below when flag is null


CREATE OR REPLACE TRIGGER "DBUSER"."TI_USERS" 
  AFTER INSERT
  on Users

  for each row

declare numrows INTEGER;
begin
    select count(*) into numrows
      from Customer
      where
        /* %JoinFKPK(:%New,Customer," = "," and") */
        :new.Customer_Key = Customer.Customer_Key;
    if (
      /* %NotnullFK(:%New," is not null and") */

      numrows = 0
    )
    then
      raise_application_error(
        -20002,
        'Cannot INSERT Users because Customer does not exist.'
      );
    end if;



end;
ALTER TRIGGER "SIMPLEX"."TI_USERS" ENABLE
4

2 に答える 2

2

ブロック全体をif :new.flag is not null then ... end if;

于 2013-03-27T20:51:21.977 に答える
2
CREATE OR REPLACE TRIGGER "DBUSER"."TI_USERS" 
  AFTER INSERT
  on Users

  for each row

declare numrows INTEGER;
begin

IF ( :new.flag IS NOT NULL ) Then

    select count(*) into numrows
      from Customer
      where
        /* %JoinFKPK(:%New,Customer," = "," and") */
        :new.Customer_Key = Customer.Customer_Key;
    if (
      /* %NotnullFK(:%New," is not null and") */

      numrows = 0
    )
    then
      raise_application_error(
        -20002,
        'Cannot INSERT Users because Customer does not exist.'
      );
    end if;

end if;

end;
ALTER TRIGGER "SIMPLEX"."TI_USERS" ENABLE
于 2013-03-27T20:48:55.477 に答える