oracle alter user password replace in stored procedure code example

Example: ORACLE STORED PROCEDURE TO ALTER PASSWORD

create or replace procedure SysChangePassword(
  pUserName in varchar2, 
  pPassWord in Varchar2) as
begin
  -- Check for system users here and reject
  if upper(pUserName) in ('SYS','SYSTEM') then
    dbms_output.put_line('not allowed');
  else
     execute immediate 'alter user '||pUserName||' identified by ' ||
           pPassWord;
    dbms_output.put_line('altered');
  end if;
  exception
     when others then
         dbms_output.put_line('error: ' || sqlerrm);
end;
/

Tags:

Misc Example