Search code examples
oracle-databasesqlplus

sqlplus: password contains slash "/" is not accepted


Maybe this is trivial for DB people but unfortunately not for me.

I spent hours with this but the solutions that I have found did not help. My DB password contains a / character and I think this confuses sqlplus and that is the reason why I am not able to log in. Let's say my password is pass/word.

This is what I have tried so far:

$ sqlplus MYUSER/pass/word@ABCDEF

$ sqlplus MYUSER/pass\/word@ABCDEF

$ sqlplus MYUSER/'pass/word'@ABCDEF

$ sqlplus MYUSER/'pass\/word'@ABCDEF

$ sqlplus MYUSER/"pass/word"@ABCDEF

$ sqlplus MYUSER/"pass\/word"@ABCDEF

$ sqlplus MYUSER/\""pass/word\""@ABCDEF

None of them above worked.

Then I tried this way:

$ sqlplus MYUSER@ABCDEF

SQL*Plus: Release 12.2.0.1.0 Production on Fri Nov 19 15:10:13 2021
Copyright (c) 1982, 2016, Oracle.  All rights reserved.

Enter password:
SP2-0306: Invalid option.
Usage: CONN[ECT] [{logon|/|proxy} [AS {SYSDBA|SYSOPER|SYSASM|SYSBACKUP|SYSDG|SYSKM|SYSRAC}] [edition=value]]
where <logon> ::= <username>[/<password>][@<connect_identifier>]
      <proxy> ::= <proxyuser>[<username>][/<password>][@<connect_identifier>]
Enter user-name: ^C

And this way:

$sqlplus /nolog
connect MYUSER@ABCDEF

SQL*Plus: Release 12.2.0.1.0 Production on Fri Nov 19 15:10:13 2021
Copyright (c) 1982, 2016, Oracle.  All rights reserved.

Enter password:
SP2-0306: Invalid option.
Usage: CONN[ECT] [{logon|/|proxy} [AS {SYSDBA|SYSOPER|SYSASM|SYSBACKUP|SYSDG|SYSKM|SYSRAC}] [edition=value]]
where <logon> ::= <username>[/<password>][@<connect_identifier>]
      <proxy> ::= <proxyuser>[<username>][/<password>][@<connect_identifier>]
Enter user-name: ^C

No result.

Google did not help.

What is the trick here that I need to use?


Solution

  • The big idea is that the first and last character of what you type needs to be ". Then the interpreters (whether it's sqlplus or the RDBMS itself) will strip them and whatever remains is taken verbatim.

    Your first four attempts aren't close but the final three are.

    $ sqlplus MYUSER/"pass/word"@ABCDEF

    This one is nearly perfect except that the shell1 gobbles up the " characters and so the forward slash is not taken verbatim.

    $ sqlplus MYUSER/"pass\/word"@ABCDEF

    This one is also close but the backslash doesn't help and the quotes are still gobbled up.

    $ sqlplus MYUSER/\""pass/word\""@ABCDEF

    Actually, this one will work but I suspect this is not precisely what you tried (i.e., it's a typo because SO handles backslashes in an unexpected way when you're quoting). In this example, the properly matched quote characters are "received" by the sqlplus main entry point.

    All of the following should work for you.

    1. Let sqlplus prompt you for the password and enter "pass/word" instead of pass/word.
    2. sqlplus myuser/\"pass/word\" so long as you set TWO_TASK=ABCDEF.
    3. sqlplus myuser/\"pass/word\"@ABCDEF # simplest imo
    4. sqlplus myuser/\""pass/word\""@ABCDEF
    5. sqlplus myuser/\""pass/word"\"@ABCDEF

    footnotes:

    1: If you're using a real operating system and not a Microsoft one.