Set the environment variable DB_PASS. It will briefly create a temp file, execute it and load the password as PSSQL variable. The file is deleted.
Then, connect to the DB and run custom.sql.
set DB_PASS=secret
sqlplus /nolog @run_custom.sql| -- in "Command Prompt" | |
| -- set DB_PASS=secret | |
| -- sqlplus /nolog @run_custom.sql | |
| host echo define DB_PASS=%DB_PASS% > db_pass.sql | |
| @@db_pass.sql | |
| host del DB_PASS.sql /q | |
| whenever sqlerror exit sql.sqlcode; | |
| define USERNAME='dummy' | |
| define TNS_STRING = '@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=example.com)(PORT=1234)(LOAD_BALANCE=YES|NO))(CONNECT_DATA=(SERVICE_NAME=db_service)))' | |
| define CONNECT_STRING=&USERNAME./"&DB_PASS"&TNS_STRING; | |
| PROMPT Connecting as &USERNAME&TNS_STRING; | |
| connect &CONNECT_STRING | |
| -- output as csv | |
| -- set markup csv on | |
| -- doesn't show how many lines at the end of the file | |
| -- set feedback off | |
| -- don't print results to terminal | |
| -- set term OFF | |
| @@custom.sql | |
| / | |
| exit; |