为什么触发器不工作? 贴有代码,请各位帮忙.

边城cn 2008-04-16 11:29:28
--功能说明:当宾馆插入数据,或修改宾馆名称时,触发器自动生成宾馆名称的拼音名称.
--但现在此功能不功作,不知是否NEW.HOTEL_NO 这里有问题呢.

create or replace trigger TRG_TEST_HOTEL_PINYIN
after insert or update on TEST_HOTEL for each row
begin
if inserting then
update TEST_HOTEL set n_hotel_pinyin=get_pinyin(:new.hotel_name)
where hotel_no= :new.hotel_no;
commit;
else -- if updating
update TEST_HOTEL set n_hotel_pinyin=get_pinyin(:new.hotel_name)
where hotel_no= :old.hotel_no;
commit;
end if;
exception
when others then
htp.print('error='||SQLERRM);
end;
...全文
88 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
边城cn 2008-04-17
  • 打赏
  • 举报
回复
[doer_ljy] 兄的代码有些问题,
'REFERENCING OLD AS OLD NEW AS NEW ' 这句代码已去掉了.

修改如下:测试通过.


create or replace trigger TRG_TEST_HOTEL_PINYIN
BEFORE insert or update
on TEST_HOTEL for each row
begin
:new.n_hotel_pinyin:=get_pinyin(:new.hotel_name);
exception
when others then
htp.print('error='||SQLERRM);
end;


奋斗并快乐着 2008-04-17
  • 打赏
  • 举报
回复
记得在TEST_HOTEL的trigger里不能对TEST_HOTEL本身进行操作吧
yaiger 2008-04-16
  • 打赏
  • 举报
回复
而且不能用COMMIT
doer_ljy 2008-04-16
  • 打赏
  • 举报
回复
在处罚期里不能对正在操作的标在进行select等操作了。
create or replace trigger TRG_TEST_HOTEL_PINYIN
before insert or update
REFERENCING OLD AS OLD NEW AS NEW
on TEST_HOTEL for each row
begin
:new.n_hotel_pinyin=get_pinyin(:new.hotel_name);
exception
when others then
htp.print('error=' ¦ ¦SQLERRM);
end;

17,090

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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