What's wrong with the insert statement in a trigger? [message #370071] |
Sat, 09 December 2000 04:47 |
wyshuai
Messages: 13 Registered: December 2000
|
Junior Member |
|
|
I wang to insert values into table t_2 with the trigger of one table,if the new value of "id" inserted into t_1 cannot be found in t_2 .as follows:
create table t_1 (id char(10) not null,age number(10),primary key(id));
create table t_2 (id char(10) not null,age number(10),primary key(id));
The trigger is that:
create trigger tr_1
before insert
on t_1
for each row
declare
var_num number(10) := 0;
begin
select 1
into var_num
from t_2
where t_2.id = :new.id;
if var_num = 0 then
insert into t_2
values
(:new.id,:new.age);
end if;
end;
I hunger for your answers.Thank you !
|
|
|