首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

oracle 触发器的更新两张数据表解决方案

2012-03-01 
oracle 触发器的更新两张数据表我想通过插入一张表的信息时候更新另一张表,该怎么弄呢,求教,如下数据:drop

oracle 触发器的更新两张数据表
我想通过插入一张表的信息时候更新另一张表,该怎么弄呢,求教,如下数据:
drop table t_info;
create table t_info(
infoid number(3) primary key,
infoname char(20),
static char(20));

drop table t_lent;
create table t_lent(
lentid number(3) primary key,
infoid number(3),
lentname char(20) not null
);

insert into t_info values(1,'洗衣机','可用');
insert into t_info values(2,'电冰箱','可用');
create trigger lenttoinfo
after insert on t_lent for
each row
begin
update t_info
set static:='已使用' where infoid = old.infoid;
end;
insert into t_lent values(1,1,'洗衣服');
请问为什么我的触发器不正确呢,怎么写才正确呢。
我想要的结果插t_lent表时候,t_info表标记已使用。

[解决办法]
没弄懂你的意思。是要在插入t_lent表的时候同时更新t_info表吗?如果是,代码如下
create trigger lenttoinfo
after insert on t_lent for
each row
begin
update t_info
set static='已使用' where infoid = old.infoid;
end;
[解决办法]
create trigger lenttoinfo
after insert on t_lent for
each row
declare
begin
update t_info
set static='已使用' where infoid = :new.infoid;
end;
[解决办法]
实测修改编译通过:

SQL code
CREATE TRIGGER lenttoinfoAFTER INSERT ON t_lent FOR EACH ROWBEGIN    UPDATE t_info SET STATIC ='已使用' WHERE infoid = :old.infoid;END; 

热点排行
Bad Request.