Friday, March 26, 2021

get list of user accounts - either unlocked or password is expired.

 

SELECT    

     'ALTER '||

     SUBSTR(DBMS_LOB.SUBSTR(DBMS_METADATA.GET_DDL('USER',USERNAME),

     INSTR(DBMS_LOB.SUBSTR(DBMS_METADATA.GET_DDL('USER',USERNAME),500),'DEFAULT')-1) ,

     INSTR(DBMS_LOB.SUBSTR(DBMS_METADATA.GET_DDL('USER',USERNAME),500),'USER')) USER_PASS , USERNAME, PROFILE 

FROM  DBA_USERS 

WHERE USERNAME IN 

     (SELECT USERNAME  

      FROM DBA_USERS 

      WHERE (USERNAME  in

            (select username  from dba_users where (account_status like '%EXPIRED%' or account_status like '%LOCK%'))));