create or replace procedure usr_test(usr_id varchar2, login_stat out varchar2) is
l_usr_id varchar2(1000);
l_stat varchar2(5);
l_last_date date;
l_current_date date;
begin
select active into l_stat from users where u_id = usr_id;
if l_stat = 0 then
login_stat := 'N';
dbms_output.put_line('User status is inactive,can not login');
else
select max(l_time) into l_last_date from login where l_id = usr_id;
select sysdate into l_current_date from dual;
if l_current_date - l_last_date > 60 then
update users set active = 0 where u_id = usr_id;
login_stat := 'N';
dbms_output.put_line('User status is inactive,can not login');
else
login_stat := 'Y';
dbms_output.put_line('login successfully');
end if;
end if;
end usr_test;
------解决方案-------------------- 初步想法,定期遍历user表的数据。
create or replace procedure XX
as
CURSOR cur_l is
select l_id,l_time from login ;
begin
for r_cur_l in cur_l loop
exit when cur_l%notfound or cur_l%notfound is null;
if sysdate -to_date( r_cur_l.l_time,'yyyymmdd')>60 then
update users set active=0 where u_id=r_cur_l.l_id;
end if;
end loop;
end;
如果可以直接获取l_id,也可以直接update了。 ------解决方案-------------------- update users t set active=0
where active=1
and not exists(select 1 from login where i_id=t.u_id and l_time>sysdate-60);
commit;
需要用存储过程的话就加上begin end;