Oracle自增ID的实现

发表于:2010-1-19 10:21

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:未知    来源:51Testing软件测试网采编

  ###建自动更新的触发器###

  CREATE OR REPLACE TRIGGER "SPORTS"."SPORTS_LINEUP_ID_TRIGGER"
  BEFORE INSERT ON "SPORTS"."LINEUP" FOR EACH ROW
  DECLARE
  next_id NUMBER;
  BEGIN
  --Get the next id number from the sequence
  SELECT sports_lineup_id_seq.NEXTVAL INTO next_id FROM dual;
  --Use the sequence number as the primarykey
  --for there cord being inserted.
  :new.id:=next_id;
  END;

  ###建保护PRIMARYKEY的触发器###

  CREATE OR REPLACE TRIGGER "SPORTS"."LINEUP_ID_UPDATE_TRIGGER"
  BEFORE UPDATE OF "ID" ON "SPORTS"."LINEUP" FOR EACHROW
  BEGIN
  RAISE_APPLICATION_ERROR(-20000,
  'sports_lineup_id_update_trigger:Update sof the ID field'
  ||'arenotallowed.');
  END;

  ###建删除的触发器###

  create or replace trigger tr_bis_exc_req_del
  before delete
  on bis_exc_req
  referencing old as old new as new
  for each row
  begin
  if :old.check_status = '3' then
  raise_application_error (-20001,'*****!');
  return;
  end if;
  end;

  ###建更新的触发器###

  create or replace trigger tr_bis_exc_req_upd
  before update
  on bis_exc_req
  referencing old as old new as new
  for each row
  begin
  if :old.check_status = '3' then
  raise_application_error (-20001,'*******!');
  return;
  end if;
  end;

33/3<123
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号