Skip to Main Content

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Massimo.

Asked: January 16, 2018 - 12:32 pm UTC

Last updated: April 20, 2022 - 12:32 pm UTC

Version: 11.2.0.1

Viewed 10K+ times! This question is

You Asked

I have to launch SQL Plus using command line options with user/password.
If connection don't work, SQL Plus don't terminate the execution, but ask for another login:

>> SQL*Plus: Release 11.2.0.1.0 Production on Mar Gen 16 13:26:00 2018
>>
>> Copyright (c) 1982, 2010, Oracle. All rights reserved.
>>
>> ERROR:
>> ORA-12560: TNS: protocol adapter error
>>
>> Immettere il nome utente: _

It's possible to tell SQL Plus to terminate without prompting for another login?
Thank you in advance.

and Chris said...

Here's one way around this:

- Start SQL*Plus without connecting (/nolog)
- set "whenever sqlerror exit"
- Try and connect

If this fails, you'll get an exception. And the sqlerror setting will kick you out:
C:\Users\csaxon>sqlplus /nolog

SQL*Plus: Release 12.2.0.1.0 Production on Tue Jan 16 13:59:47 2018

Copyright (c) 1982, 2016, Oracle.  All rights reserved.

SQL> whenever sqlerror exit
SQL> conn chris/wrong@db
ERROR:
ORA-01017: invalid username/password; logon denied



C:\Users\csaxon>


Of course, this implies you're storing username/passwords in scripts. This is a security risk. A better method is to use a wallet:

https://oracle-base.com/articles/10g/secure-external-password-store-10gr2

Rating

  (3 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Another option...

Oren Nakdimon, January 16, 2018 - 3:14 pm UTC

sqlplus -L user/pwd
Chris Saxon
January 17, 2018 - 1:56 pm UTC

Thanks Oren, didn't know that one!

Great Solution for preventing tasks t to hang out

Andres, May 09, 2019 - 1:57 pm UTC

I have few recurrent tasks running on my server running sql query's and one of my problem was when the DB gets down the process was hanging out forever until I killed the process

Thank you !!!

Jitender Singh, April 20, 2022 - 6:45 am UTC

Was looking for a solution related to this for 2-3 days, found it here. Thanks !!!
Chris Saxon
April 20, 2022 - 12:32 pm UTC

Glad we could help