oracle触发器没有效果,触发器不起作用,各位帮忙看看什么原因?

测试数据模型如下:

Create Table test_c (

Id Number,

seq Number,

state varchar2(5)

);

select a.*,rowid from test_c a

Insert Into test_c

Values(1011,101,'00A');

Insert Into test_c

Values(1012,101,'00A');

Insert Into test_c

Values(1021,102,'00A');

Insert Into test_c

Values(1022,102,'00A');

Commit;

Create Table test_d (

Id1 Number,

Id2 Number,

state varchar2(5)

);

Insert Into test_d

Values(1011,1012,'00A');

Insert Into test_d

Values(1011,1013,'00A');

Insert Into test_d

Values(1012,1011,'00A');

Insert Into test_d

Values(1012,1013,'00A');

Insert Into test_d

Values(1013,1011,'00A');

Insert Into test_d

Values(1013,1012,'00A');

Insert Into test_d

Values(1021,1022,'00A');

Insert Into test_d

Values(1022,1021,'00A');

Commit;

create table TRIGGER_LOG(

ERROR_ID     VARCHAR2(10),

ERROR_CLAUSE VARCHAR2(500),

ERROR_DATE   DATE

);

实现的需求为:插入表test_c一条ID=1013的记录,然后使用触发器将表test_d的ID1=1013且ID2满足条件

id2 In(

Select Id from test_c where seq=101 And state='00A'

)

的记录的状态更新为00X。

触发器如下创建:

--

Create Or Replace Trigger test_c_air

After Insert ON test_c

For Each Row

Declare

--v_old_state varchar2(5);

v_new_state varchar2(5);

--v_old_id Number;

v_new_id Number;

--v_old_seq Number;

v_new_seq Number;

Begin

v_new_id:=:new.id;

v_new_seq:=:new.seq;

v_new_state:=:new.state;

If v_new_seq =101 And v_new_state='00A'

Then

Update test_d c

Set c.state='00X'

where c.id1= v_new_id

And c.id2 In(

Select Id from test_c where seq=101 And state='00A'

)

And c.state='00A';

Else

Insert Into trigger_log(error_id,error_clause,error_date)

Values('-20011','插入无关数据,不执行触发器!',Sysdate);

End If;

exception

when others then

Null;

End  test_c_air;

--具体执行结果如下:

Insert Into test_c

Values(1013,101,'00A');

commit;

select a.* from test_c a where Id=1013 --已插入一条记录

select a.* from test_d a where id1=1013 --状态未发生变化

select a.* from TRIGGER_LOG a --未写入任何日志

各位帮忙看看,是不是表test_c不能重复调用在触发器里面?该如何改正?谢谢了!

你可能感兴趣的:(oracle触发器没有效果)