在插入一条数据的时候,根据这条数据修改其中的内容并插入
create or replace trigger tri_selectedcourse
before insert on selectedcourse
for each row
declare
teachername varchar2(20);
begin
select u.name
into teachername
from BeginSchedule b, userinfo u
where b.tearcherid = u.userid
and b.beginscheduleid = :new.beginscheduleid
and b.coursecode = :new.coursecode;
:new.courseteacher := teachername;
end;
我写了这样一个触发器,但是触发器好像不能获取到当前记录的内容,求个思路,希望的是批量插入数据的时候,在数据库中找一个字段的内容修改到本条数据中。
------解决方案--------------------直接用set试试呢:
SQL code
create or replace trigger tri_selectedcourse
before insert on selectedcourse
for each row
begin
declare teachername varchar2(20);
select u.name
into teachername
from BeginSchedule b, userinfo u
where b.tearcherid = u.userid
and b.beginscheduleid = new.beginscheduleid
and b.coursecode = new.coursecode;
set new.courseteacher = teachername;
end;
------解决方案--------------------
使用临时表,
先插入临时表,然后进行update,插入目标表,清空临时表。