oracle中创建触发器错误,

小村长 2012-06-10 01:23:06
创建INSERT触发器t_inst_stu:在学生表(student)中每新增一名学生,若其班级编号非空,则将班级表(class)中相应班级的人数(c_total)自动加1。
这是我的代码
create or replace trigger t_inst_stu after insert on student
referencing old as old_value
new as new_value
for each row
when (new_value.clsno is not null)
begin
update class set c_total=c_total+1 where clsno=:new_value.clsno;
end;
现在的问题是当执行插入语句时,没反应,求大神指导。
...全文
116 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
huangdh12 2012-06-10
  • 打赏
  • 举报
回复
我改成
create or replace trigger t_inst_stu after insert on student

for each row
begin
case when :new.clsno is not null then

update class set c_total=c_total+1 where clsno=:new.clsno;
end case;
end;

你再试试。 这样好像可以。
小村长 2012-06-10
  • 打赏
  • 举报
回复
问题应该是:new_value.clsno在begin...end中不能被识别
小村长 2012-06-10
  • 打赏
  • 举报
回复
不行 显示无效触发器。 我的那个触发器没有错误,现在关键是where clsno=:new_value.clsno;就是new_value.clsno不能将其赋值给clsno、、
huangdh12 2012-06-10
  • 打赏
  • 举报
回复
这个触发器应该是无效的吧 select status from user_objects t where t.object_name='T_INST_STU' 看看状态是什么。
另 试试

create or replace trigger t_inst_stu after insert on student
referencing old as old_value
new as new_value
for each row
case when new_value.clsno is not null then
begin
update class set c_total=c_total+1 where clsno=:new_value.clsno;
end case;
end ;

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧