Wednesday, December 23, 2015

How to login to user when you don't know the password in Oracle

   steps :-

  1.    select dbms_metadata.get_ddl('USER','SCOTT') from dual;
  2.    change password
  3.    connect 
  4.    do the work
  5.    change it back
  6.    revert back to original password from step 1

How to reset password in Oracle after the current password has expired

declare
 cursor pass is 
SELECT    
     'ALTER '||
     SUBSTR(DBMS_LOB.SUBSTR(DBMS_METADATA.GET_DDL('USER',USERNAME),
     INSTR(DBMS_LOB.SUBSTR(DBMS_METADATA.GET_DDL('USER',USERNAME),200),'DEFAULT')-1) ,
     INSTR(DBMS_LOB.SUBSTR(DBMS_METADATA.GET_DDL('USER',USERNAME),200),'USER')) USER_PASS 
FROM  DBA_USERS 
WHERE USERNAME IN 
     (SELECT USERNAME  
      FROM DBA_USERS 
      WHERE (USERNAME  in
            (select username  from dba_users where account_status like '%EXPIRED%' and
              (
               username like 'SYSTEM' or 
               username like 'TEST%' ))));

BEGIN
  for rec in pass loop
   begin
    execute immediate rec.USER_PASS;
    exception when others then DBMS_OUTPUT.PUT_LINE(SQLERRM);
   end;
  end loop;
END;
/