SQL> connect test/test
Connected.
set serveroutput on
create or replace procedure Change_pw (uname in varchar2, pw in varchar2) is
insufficient_privs exception;
pragma exception_init(insufficient_privs,-1031);
begin
if UPPER(uname) in ('SYS','SYSTEM') then
raise insufficient_privs;
else
execute immediate ('alter user '||uname||' identified by '||pw);
dbms_output.put_line('Changed password for user: '||uname);
end if;
end;
/
Procedure created.
grant execute on change_pw to yada
/
Grant succeeded.
SQL> conn yada/yada
Connected.
SQL> select granted_role from user_role_privs;
GRANTED_ROLE
------------------------------
CONNECT
PLUSTRACE
RESOURCE
SQL> alter user test2 identified by test2;
alter user test2 identified by test2
*
ERROR at line 1:
ORA-01031: insufficient privileges
SQL> exec test.change_pw('test2','yada')
PL/SQL procedure successfully completed.
SQL> exec test.change_pw('sys','yada')
BEGIN test.change_pw('sys','yada'); END;
*
ERROR at line 1:
ORA-01031: insufficient privileges
ORA-06512: at "TEST.CHANGE_PW", line 6
ORA-06512: at line 1
conn test2/yada
Connected.
SQL>