Skip to content

Commit d674fb4

Browse files
committed
This Creates two procedures, one shows all users and the last time their password was changed, the second allows you to specify one user to view
1 parent 953484f commit d674fb4

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

proc_last_change.sql

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
REM Filename : proc_last_change.sql
2+
REM Author : Craig Richards
3+
REM Created : 14-Feburary-2012
4+
REM Version : 1.0
5+
REM Modifications :
6+
REM
7+
REM Description : Creates two procedures which shows you the last time a password was changed.
8+
REM The First last_change_all, when called will show you all the users with the last date
9+
REM The next last_change, when called you pass the user and it displays the details for that user
10+
11+
REM Instructions : For last_change call it by exec last_change('username')
12+
13+
CREATE OR REPLACE PROCEDURE last_change_all
14+
AUTHID CURRENT_USER
15+
AS
16+
17+
-- Variable Declaration
18+
19+
lv_user sys.user$.user#%TYPE;
20+
lv_name sys.user$.name%TYPE;
21+
lv_ptime sys.user$.ptime%TYPE;
22+
23+
-- Create the cursor
24+
25+
CURSOR c_user IS
26+
SELECT user#, RPAD(name,24,' '), ptime FROM sys.user$ WHERE ptime IS NOT NULL;
27+
28+
-- Output the Information
29+
30+
BEGIN
31+
OPEN c_user;
32+
DBMS_OUTPUT.PUT_LINE(CHR(10));
33+
DBMS_OUTPUT.PUT_LINE('This displays the usernames and the date the password was last changed');
34+
DBMS_OUTPUT.PUT_LINE('======================================================================');
35+
DBMS_OUTPUT.PUT_LINE(CHR(10));
36+
DBMS_OUTPUT.PUT_LINE('USERNAME' || CHR(9) || CHR(9) || 'LAST CHANGED');
37+
DBMS_OUTPUT.PUT_LINE('========' || CHR(9) || CHR(9) || '============');
38+
LOOP
39+
FETCH c_user INTO lv_user, lv_name, lv_ptime;
40+
EXIT WHEN c_user%NOTFOUND;
41+
DBMS_OUTPUT.PUT_LINE(lv_name || lv_ptime);
42+
END LOOP;
43+
CLOSE c_user;
44+
END last_change_all;
45+
/
46+
47+
SHOW ERROR
48+
49+
CREATE OR REPLACE PROCEDURE last_change (inp_user VARCHAR2)
50+
AUTHID CURRENT_USER
51+
AS
52+
53+
-- Variable Declaration
54+
55+
lv_user sys.user$.user#%TYPE;
56+
lv_name sys.user$.name%TYPE;
57+
lv_ptime sys.user$.ptime%TYPE;
58+
59+
-- Create the CURSOR
60+
61+
CURSOR c_user IS
62+
SELECT user#, name, ptime FROM sys.user$ WHERE UPPER(name) = UPPER(inp_user);
63+
64+
-- Output the Information
65+
66+
BEGIN
67+
OPEN c_user;
68+
LOOP
69+
FETCH c_user INTO lv_user, lv_name, lv_ptime;
70+
EXIT WHEN c_user%NOTFOUND;
71+
DBMS_OUTPUT.PUT_LINE(CHR(10));
72+
DBMS_OUTPUT.PUT_LINE('Last change for ' || inp_user || ' was ' || lv_ptime);
73+
END LOOP;
74+
CLOSE c_user;
75+
END last_change;
76+
/

0 commit comments

Comments
 (0)