I am running a script that "creates/replaces" a procedure in a database and then runs the procedure. The code is as below:
WHENEVER SQLERROR EXIT
UNDEFINE g_cust_pwd
UNDEFINE g_db_name
SPOOL 'output'
PROMPT setup_and_run.sql begin
ACCEPT g_db_name CHAR PROMPT 'Please enter the DB instance: '
ACCEPT g_cust_pwd PROMPT 'Please enter the TEST_SCHEMA schema password: ' HIDE
PROMPT Testing connection
CONNECT TEST_SCHEMA/&&g_cust_pwd@&&g_db_name
WHENEVER SQLERROR CONTINUE
SET SERVEROUTPUT ON
SET DEFINE OFF
PROMPT
PROMPT @procedure_test.prc
PROMPT Creating or Replacing Procedure
@procedure_test.prc
PROMPT
PROMPT procedure_test
PROMPT Running Procedure...
EXEC procedure_test
PROMPT setup_and_run.sql complete
SPOOL OFF
UNDEFINE g_cust_pwd
UNDEFINE g_db_name
/
Whenever I run the code above with the correct credentials (double, triple checked these to make sure that this isn't the issue). The code works fine, as expected, the problem occurs whenever I run the code for a second time in the same SQLPlus session it gives a TNS error.
Normally, I would assume that this is merely a TNS names error and the database needs to be added to the list, but it works only once per session (even if I add a disconnect at the end)
g_db_name
has previous value as you have entered first time? The connect identifier you have supplied couldn't be resolved using tnsname.ora file hence the error.