Skip to content

Instantly share code, notes, and snippets.

@dolphinotaku
Last active June 21, 2020 14:09
Show Gist options
  • Save dolphinotaku/b49e5de75824931b2eee1385ae0e7f91 to your computer and use it in GitHub Desktop.
Save dolphinotaku/b49e5de75824931b2eee1385ae0e7f91 to your computer and use it in GitHub Desktop.
this will use external oracle sql client to update database account password, call update_pwd.bat %oldpwd% %newpwd%
--spool d:\sql_execuste.log
-- write sql here
-- if password complexity verification function has been enabled
alter user &1 identified by &2 replace &3
-- if password verification is disabled
-- alter user <user> identified by <password>;
-- execute the sql
/
--spool off;
-- exit SQL client
exit
set "sqlclient=C:\instantclient_19_6_win_x64"
set "_DB_HOST=yourDBhost_name_or_ip"
set "_DB_PORT=yourport"
set "_DB_NAME=database_name"
set "_DB_USER=database_login_user"
set "_DB_PWD=user_password"
:: initialize currenct date time variable
for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a
set YYYY=%dt:~0,4%
set MM=%dt:~4,2%
set DD=%dt:~6,2%
set HH=%dt:~8,2%
set Min=%dt:~10,2%
set Sec=%dt:~12,2%
:: set stamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%
:: set stamp=%YYYY%%MM%%DD%
set _STAMP=%YYYY%-%MM%-%DD%_%HH%%Min%%Sec%
:: this batch script use external oracle sql client to update the db pwd
call config.bat
set "oldpwd=%1"
set "newpwd=%2"
"%sqlclient%\sqlplus.exe" %_DB_USER%/%_DB_PWD%@//%_DB_HOST%:%_DB_PORT%/%_DB_NAME% @"%cd%\changepwd.sql" %_DB_USER% %newpwd% %oldpwd% > logs\%_STAMP%.sql_alter_user.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment