表
user
(
user_id varchar2(20), --用户ID
reg_time date, --注册日期
quit_time date, --注销日期
last_time date --最后一次注册日期
)stat
(
user_id varchar2(20), --用户ID
reg_time date --注册日期
quit_count number, --注销次数
rereg_count number, --重新注册次数
)
1。当向表user插入新记录时,在表stat中新建一行,其中表stat的reg_time为当前日期,quit_count和rereg_count都为0.
2。当更新表user时,如果是将quit_time的值更新为空,将表stat中rereg_count的值加一。如果是将user.quit_time的值更新为当前日期,将表stat中quit_time的值加一。
user
(
user_id varchar2(20), --用户ID
reg_time date, --注册日期
quit_time date, --注销日期
last_time date --最后一次注册日期
)stat
(
user_id varchar2(20), --用户ID
reg_time date --注册日期
quit_count number, --注销次数
rereg_count number, --重新注册次数
)
1。当向表user插入新记录时,在表stat中新建一行,其中表stat的reg_time为当前日期,quit_count和rereg_count都为0.
2。当更新表user时,如果是将quit_time的值更新为空,将表stat中rereg_count的值加一。如果是将user.quit_time的值更新为当前日期,将表stat中quit_time的值加一。
after insert or update on user
for each row
begin
if inserting then
insert into stat values(:new.user_id,sysdate,0,0);
end if;
if updating then
if :new.quit_time is null then
update stat
set rereg_count=rereg_count+1;
else
update stat
set quit_count =quit_count+1;
end if;
end if;
end;
after insert or update on user
for each row
begin
if inserting then
insert into stat values(:new.user_id,sysdate,0,0);
elsif updating then
if :new.quit_time is null then
update stat set rereg_count=rereg_count+1;
elsif :new.quit_time=to_date(sysdate,'yyyy-mm-dd') then
update stat set quit_count =quit_count+1;
end if;
end if;
end;