How to create an Oracle stored procedure to lock user accounts not logged onto database for more than 90 days

匆匆过客 提交于 2019-12-11 06:07:56

问题


How do I create an Oracle Stored Procedure to lock user accounts that's not logged onto the database for more than 90 days?

I assumed that I could create a Profile Object and list the Resource Parameters in my database but I am using Oracle 11g and it appears that feature doesn't exist.

This is what I tried so far:

select username from dba_audit_trail
where  action_name = 'LOGON'
group  by username
having max(timestamp) < sysdate - 90

I also attempted to create a profile attempting to use INACTIVE_ACCOUNT_TIME as my Resource Parameters but it does not exist in Oracle 11g:

CREATE PROFILE time_limit LIMIT 
INACTIVE_ACCOUNT_TIME 90;

回答1:


For 12c it can be:

begin
for x in 
(select username
  from dba_users
  where last_login < sysdate - 90) 
loop
  execute immediate 'alter user ' || x.username || ' account lock';
end loop;
end;

If you're using 11g you may try your query for loop:

begin
for x in 
(select username from dba_audit_trail
 where  action_name = 'LOGON'
 group  by username
 having max(timestamp) < sysdate - 90) 
loop
  execute immediate 'alter user ' || x.username || ' account lock';
end loop;
end;


来源:https://stackoverflow.com/questions/41829385/how-to-create-an-oracle-stored-procedure-to-lock-user-accounts-not-logged-onto-d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!