【點(diǎn)擊:】
阿木伯 著
|
快照和觸發(fā)子結(jié)合使用的例子 |
|
- 軟件環(huán)境:
1、Windows NT4.0+ORACLE 8.0.4
2、ORACLE安裝路徑為:C:\ORANT
- 需求說明:
大型商場(chǎng)、超市中,都會(huì)有計(jì)算機(jī)管理系統(tǒng),很多都用到了Oracle數(shù)據(jù)庫,
此行業(yè)中有一個(gè)商品庫存管理的問題,因?yàn)樯唐贩N類特別多(超過10萬種),
一般庫存表中記載的是只是當(dāng)日庫存,那么如何記錄歷史庫存呢?
- 實(shí)現(xiàn)方法:
SQL*Plus中
create table 當(dāng)前庫存表(
spbm char(6), --商品編碼
kcsl number --庫存數(shù)量
);
create table 歷史庫存表(
rq char(8), --日期
spbm char(6), --商品編碼
kcsl number --庫存數(shù)量
);
drop snapshot 計(jì)算快照;
create snapshot 計(jì)算快照 refresh next round(sysdate+0.5)+116/144
as
select * from dual;
--每天晚19:20執(zhí)行,這個(gè)快照什么也不做,只是為了觸發(fā)下面的觸發(fā)子,因?yàn)樵谶@個(gè)快照刷新的時(shí)候,有新記錄產(chǎn)生
create or replace trigger 記錄歷史庫存觸發(fā)子 before insert on snap$_計(jì)算快照 for each row
begin
insert into 歷史庫存表(rq,spbm,kcsl)
select to_char(sysdate,'yyyymmdd'),spbm,kcsl from 當(dāng)前庫存表;
exception when others then
raise_application_error(-10000,'不能記錄歷史庫存');
end;
/
以上只是一種方法,主要目的是介紹快照和觸發(fā)器結(jié)合使用的方法。
|
【最后更新:】 |
|