oracle 触发器、备份

 dbms_random.value(20,30) round()   //取整

create table testinx(          

  id number,          

  tname varchar(20),          

  constraint pk_t primary key(id)  //设置主键

 )

触发器:  

  insert  

  delete  

  update   //基于这三个操作

行级触发器

表级触发器  

  create or replace trigger 名字  

  after insert //增之后  on 表名  

  (for each row //表示行级触发器,不写就是表级)  

  (declare  //声明变量 可不写)  

  begin   

    dbms_output.put_line('');  

  end;    

  select to_char(sysdate,'day') from dual  //取系统时间,周几  

  select to_char(sysdate,'hh24') from dual //取系统时间,几点

非工作时间不允许插入数据:  

  create or replace trigger 名字  

  before insert  on 表名  

  begin   

  if    

    (to_char(sysdate,'day') not in ('星期六','星期日')    and    to_char(sysdate,'hh24') between 10 and 17)   

  then    

    raise_application_error(-20001,'非工作时间不允许插入数据');  //抛出异常   

  end if;  

  end;    

备份:  

  :old //增删改之前的那一行数据的对象    

  :new //增删改之后的那一行数据的对象  

  create table 表名新 as select * from 表名

   create or replace trigger 触发器名  

  after insert or update or delete  on 表名

  for each row  

  begin   

  if inserting then    

    insert into 表名新 values(:new.sno,……);   

  elsif update then    

    update 表名新 s set s.sname=:new,sname,……   

  else    

    delete 表名新 s3 where s3.sno=:new.sno   

  end if;  

  end

原文地址:https://www.cnblogs.com/gonghuixin/p/7009325.html