-
Notifications
You must be signed in to change notification settings - Fork 0
/
login functions.sql
86 lines (57 loc) · 1.57 KB
/
login functions.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
create or replace package log_in_package as
procedure show_login_log;
procedure login_log(emp_id in employee.eid%TYPE);
function login(user_name employee.name%TYPE, pass employee.password%TYPE)
return number;
function logout(emp_id employee.eid%TYPE)
return number;
end log_in_package;
/
create or replace package body log_in_package as
procedure show_login_log
IS
cursor c is select * from log_in_history ORDER BY log_time DESC;
begin
for r in c loop
dbms_output.put_line(to_char(r.eid)|| ' ' || to_char(r.log_time) || ' ' || to_char(r.status));
end loop;
end show_login_log;
procedure login_log(emp_id in employee.eid%TYPE)
IS
begin
insert into log_in_history (eid,status) values(emp_id,0);
end login_log;
function login(user_name employee.name%TYPE, pass employee.password%TYPE)
return number
is
up employee.password%TYPE;
emp_id employee.eid%TYPE;
yes number;
BEGIN
--up := 'NONE';
yes := 0;
select password,eid into up,emp_id from employee where name = user_name;
if( up = pass ) then
yes := 1;
login_log(emp_id);
end if;
return yes;
exception
when no_data_found then
return yes;
END login;
function logout(emp_id employee.eid%TYPE)
return number
is
yes number;
BEGIN
yes := 0;
update log_in_history set status = 1 where eid = emp_id and status = 0;
yes := 1;
return yes;
exception
when no_data_found then
return yes;
END logout;
end log_in_package;
/