java oracle 触发器_Java 开发中之九:oracle中的触发器及替代触发器,作业

1、DML触发器(insert,update,delete)

思路:1加锁,回滚,抛出异常  2、before/after

create or replace trigger myt

before update on scott.emp1

declare

i varchar2(20);

begin

select to_char(sysdate,'day') into i from dual;

if(trim(i)='星期六' or trim(i)='星期日') then

raise_application_error(-20006,'不能在周末修改数据');

end if;

end;

create trigger tri_update

before update on emp1

for each row --只有行触发时才有:new (insert update) :old(delete ,update)的值

declare

begin

if abs(:new.sal-:old.sal)/:old.sal>0.1 then

end if;

end;

案例

create trigger mytt before insert on jiaoyi for each row

declare

kk number; --得到已有库存

begin

if :new.jtype='in' then

update kuncun set ptot=ptot+:new.jnum where pid=:new.jid;

else

select ptot in kk from kuncun where pid=:new.jid;

if(kk>=:new.jnum) then

update kuncun set ptot=ptot-:new.jnum where pid=:new.jid;

else

dbms_output.put_line("库存不足");

end if;

end if;

end;

但是现在的软件系统一般不用这个东东,因为都喜欢0存库

替代触发器:触发器作用视图(1,与表---对应 。    2,汇总怕结果);

create trigger mytt instead of update on  v_emp  for each row    -----update v_emp set ss=1000  如果没有定义替换触发器这句就会报错。

delcare

begin

end;

语句的触发,有无时间    在Oralce中叫做作业 :其实就是定时的处理一个问题,相当于window中的计划任务

Oralce的内置程序包:所有者:sys

a.  dbms_JOB:作业的调度(定时执行)

步法:

1、配置初始化的参数init.ora

2、作业由几个进程进行处理      job_queue_processes = 10    #job_queue_processes = 2      这个文件在init.ora中

3、扫描作业进程的时间间隔      job_queue_interval = 60  #job_queue_interval = 10

4、熟悉DBMS_JOB

submit  change  what    next_date  remove

declare

v_job number;--自定义的变量,存储作业的编号

begin

dbms_job.submit(v_job,'scott.tmepinsert();',sysdate,'sysdate+(10/(24*60*60))');  --参数说明:v_job作业标号,第二个参数为过程,第三个是开始的时间,第四个是时间隔间

commit;

end;

这样就定义好一个作业,每隔10秒钏调一次过程:scott.tmepinsert();

select * user_jobs  --查看所有有作业

exec dbms_job.remove(v_job)-- 删除一个作业

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值