sqlplus: password contains slash "/" is not accepted - oracle

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?

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.
Let sqlplus prompt you for the password and enter "pass/word" instead of pass/word.
sqlplus myuser/\"pass/word\" so long as you set TWO_TASK=ABCDEF.
sqlplus myuser/\"pass/word\"#ABCDEF # simplest imo
sqlplus myuser/\""pass/word\""#ABCDEF
sqlplus myuser/\""pass/word"\"#ABCDEF
footnotes:
1: If you're using a real operating system and not a Microsoft one.

Related

Understanding connecting to the database through SQLPLUS

when reading the Oracle APEX documentation, I did not understand the reason it asks to connect to the database through sqlplus using sqlplus /nolog then connect sys as sysdba. If it will eventually connect with sys as sysdba, why not doing it from the beginning with sqlplus sys as sysdba command?
Here is what I am talking about:
https://docs.oracle.com/en/database/oracle/application-express/20.1/htmig/downloading-installing-Oracle-AE.html#GUID-7E432C6D-CECC-4977-B183-3C654380F7BF
I would suspect its historical. In older releases on SQL Plus, if you ran:
sqlplus my_user/my_pass
on the command line, then on unix environments someone running the 'ps' command could see those details. Even in modern versions of SQL Plus where we remove that from obvious view, then digging into things like command history could expose it.
So always best never to type user or password details on the command line.

sqlplus fails on execution from shell script, but works fine from it's execution from terminal

I have a software that runs a shell script. There is a sqlplus command among with a lot of other staff in that shell script.
sqlplus -L 'user/passwd'#\'localhost:1521/orcl\' #file_path.ddl test_cpm_user test_cpm_password CPMDAT CPMIDX
Shell scripts fails on that line above with message:
SQL*Plus: Release 11.2.0.4.0 Production on Fri Oct 12 11:50:36 2018
Copyright (c) 1982, 2013, Oracle. All rights reserved.
ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified
SP2-0751: Unable to connect to Oracle. Exiting SQL*Plus
However, if I run it by myself from terminal it works fine.
What might be a reason of such behaviour?
Try below command with braces since I see hostname contains special characters
sqlplus -L '{user}/{passwd}'#{hostname}' #file_path.ddl test_cpm_user test_cpm_password CPMDAT CPMIDX

Why does SQL plus is not showing the result on terminal even when it is executing on db successful?

I have written a bash script which connects to the db and run query. These query are fetched from a file. This was working till I was using mysql on local desktop using lampp. But now connecting db on other server using sqlplus64 is returning
SQL*Plus: Release 12.2.0.1.0 Production
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Use SQL*Plus to execute SQL, PL/SQL and SQL*Plus statements.
Usage 1: sqlplus -H | -V
-H Displays the SQL*Plus version and the
usage help.
-V Displays the SQL*Plus version.
Usage 2: sqlplus [ [<option>] [{logon | /nolog}] [<start>] ]
<option> is: [-AC] [-C <version>] [-L] [-M "<options>"] [-NOLOGINTIME] [-R <level>]
[-S]
-AC Enable Application Continuity.
-C <version> Sets the compatibility of affected commands to the
version specified by <version>. The version has
the form "x.y[.z]". For example, -C 10.2.0
-L Attempts to log on just once, instead of
reprompting on error.
-M "<options>" Sets automatic HTML or CSV markup of output. The options
have the form:
{HTML html_options|CSV csv_options}
See SQL*Plus User's Guide for detailed HTML and CSV options.
-NOLOGINTIME Don't display Last Successful Login Time.
-R <level> Sets restricted mode to disable SQL*Plus commands
that interact with the file system. The level can
be 1, 2 or 3. The most restrictive is -R 3 which
disables all user commands interacting with the
file system.
-S Sets silent mode which suppresses the display of
the SQL*Plus banner, prompts, and echoing of
commands.
<logon> is: {<username>[/<password>][#<connect_identifier>] | / }
[AS {SYSDBA | SYSOPER | SYSASM | SYSBACKUP | SYSDG | SYSKM | SYSRAC}] [EDITION=value]
Specifies the database account username, password and connect
identifier for the database connection. Without a connect
identifier, SQL*Plus connects to the default database.
The AS SYSDBA, AS SYSOPER, AS SYSASM, AS SYSBACKUP, AS SYSDG,
AS SYSKM and AS SYSRAC options are database administration privileges.
<connect_identifier> can be in the form of Net Service Name
or Easy Connect.
#[<net_service_name> | [//]Host[:Port]/<service_name>]
<net_service_name> is a simple name for a service that resolves
to a connect descriptor.
Example: Connect to database using Net Service Name and the
database net service name is ORCL.
sqlplus myusername/mypassword#ORCL
Host specifies the host name or IP address of the database
server computer.
Port specifies the listening port on the database server.
<service_name> specifies the service name of the database you
want to access.
Example: Connect to database using Easy Connect and the
Service name is ORCL.
sqlplus myusername/mypassword#Host/ORCL
The /NOLOG option starts SQL*Plus without connecting to a
database.
The EDITION specifies the value for Session Edition.
<start> is: #<URL>|<filename>[.<ext>] [<parameter> ...]
Runs the specified SQL*Plus script from a web server (URL) or the
local file system (filename.ext) with specified parameters that
will be assigned to substitution variables in the script.
When SQL*Plus starts, and after CONNECT commands, the site profile
(e.g. $ORACLE_HOME/sqlplus/admin/glogin.sql) and the user profile
(e.g. login.sql in the working directory) are run. The files may
contain SQL*Plus commands.
Refer to the SQL*Plus User's Guide and Reference for more information.
this query is duplicate and is not executed
Why am I not able to see the successful output and the error code ?
This is my bash script
RAW=`cat sqlTemp.sql`
IFS=";"
for var in $RAW
query=$(echo $var | sed '/^$/d')
do
sqlplus64 username/password#hostname:portnumber/servicename $query 2>>errorLog.txt
done
content of my sqlTemp.sql
select name from TEMP_DB_QUERY_AUTOMATIO;
select *from TEMP_DB_QUERY_AUTOMATION;
select *from TEMP_DB_QUERY_AUTOMATION;
select qlid from TEMP_DB_QUERY_AUTOMATION;
select *from TEMP_DB_QUERY_AUTOMATION;
select email TEMP_DB_QUERY_AUTOMATION;

Shell script cannot connect to Oracle since update from Oracle 8 to Oracle 10

I have a shell script that connects to a Oracle database.
function getdata {
sqlplus user/pass -s <<EOF
select c1 from t1;
exit;
EOF
}
The database has been upgraded from Oracle 8 to Oracle 10 and now the results file which should contain database results just contains the Oracle help text.
SQL*Plus: Release 10.2.0.5.0 - Production
Copyright (c) 1982,2010,Oracle. All Rights Reserved.
Usage 1: sqlplus -H | -V
-H Displays the SQL*Plus version and the
usage help.
-V Displays the SQL*Plus version.
Usage 2: sqlplus [ [<option>] [<logon>] [<start>] ]
<option> is: [-C <version>] [-L] [-M "<options>"] [-R <level>] [-S]
-C <version> Sets the compatibility of affected commands to the
version specified by <version>. The version has
the form "x.y[.z]". For example,-C 10.2.0
-L Attempts to log on just once,instead of
reprompting on error.
-M "<options>" Sets automatic HTML markup of output. The options
have the form:
HTML [ON|OFF] [HEAD text] [BODY text] [TABLE text]
[ENTMAP {ON|OFF}] [SPOOL {ON|OFF}] [PRE[FORMAT] {ON|OFF}]
-R <level> Sets restricted mode to disable SQL*Plus commands
that interact with the file system. The level can
be 1,2 or 3. The most restrictive is -R 3 which
disables all user commands interacting with the
file system.
-S Sets silent mode which suppresses the display of
the SQL*Plus banner,prompts,and echoing of
commands.
<logon> is: (<username>[/<password>][#<connect_identifier>] | /)
[AS SYSDBA | AS SYSOPER] | /NOLOG
Specifies the database account username,password and connect
identifier for the database connection. Without a connect
identifier,SQL*Plus connects to the default database.
The AS SYSDBA and AS SYSOPER options are database administration
privileges.
The /NOLOG option starts SQL*Plus without connecting to a
database.
<start> is: #<URL>|<filename>[.<ext>] [<parameter> ...]
Runs the specified SQL*Plus script from a web server (URL) or the
local file system (filename.ext) with specified parameters that
will be assigned to substitution variables in the script.
When SQL*Plus starts,and after CONNECT commands,the site profile
(e.g. $ORACLE_HOME/sqlplus/admin/glogin.sql) and the user profile
(e.g. login.sql in the working directory) are run. The files may
contain SQL*Plus commands.
Refer to the SQL*Plus User's Guide and Reference for more information.
option should be before logon so sqlplus -s user/pass

Echo sqlplus command without using prompts or scripts

I have a script which I want to maintain as a single file, however I wish to echo the commands input into sqlplus without using either PROMPT <sql> or #script.sql can this be done?
Current script:
$ cat test.sh
#!/bin/bash
LOG=/home/oracle/output.log
sqlplus hr/hr <<EOF > $LOG
set echo on
select 1 from dual;
QUIT
EOF`
Current output:
$ cat output.log
SQL*Plus: Release 11.2.0.4.0 Production on Tue Mar 1 15:01:12 2016
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options
SQL> SQL>
1
----------
1
What I want:
$ cat output.log
SQL*Plus: Release 11.2.0.4.0 Production on Tue Mar 1 15:02:02 2016
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options
SQL> SQL> SQL> select 1 from dual;
1
----------
1
When SQL*Plus is reading commands from your TTY, the echoing of input is actually handled by your TTY, not SQL*Plus. If SQL*Plus handled the echoing, any time you manually typed a command you would see the command twice (once as you typed it, once as it was echo'd back).
Additionally, the TERMOUT option only applies when running a script file, not reading from STDIN.
The easy fix is telling SQL*Plus that /dev/stdin is a script:
sqlplus scott/tiger #/dev/stdin <<EOF
SET TERMOUT ON ECHO ON
SELECT SYSDATE FROM dual;
EOF
try spool instead of redirecting your STDOUT:
#!/bin/bash
LOG=/home/oracle/output.log
sqlplus hr/hr <<EOF
set echo on term on
spool $LOG
select 1 from dual;
QUIT
EOF
To expand on wonderful #Mr.llama answer.
His construct works perfect on Solaris.
However on Linux (Oracle Linux Server release 7.9), this causes every command to run twice in sqlplus, even though it echoes the command only one time. See below:
$ sqlplus -l / as sysdba #/dev/stdin <<-EOF
> set echo on termout on
> select systimestamp from dual;
> EOF
SQL*Plus: Release 19.0.0.0.0 - Production on Wed Feb 23 14:33:03 2022
Version 19.11.0.0.0
Copyright (c) 1982, 2020, Oracle. All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.11.0.0.0
SQL> select systimestamp from dual;
SYSTIMESTAMP
---------------------------------------------------------------------------
23-FEB-22 02.33.03.975542 PM -08:00
SQL> SQL>
SYSTIMESTAMP
---------------------------------------------------------------------------
23-FEB-22 02.33.03.976106 PM -08:00
SQL> Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.11.0.0.0
Notice how there are two systimestamp lines, with different timestamps, which means that the select was executed twice.
This double execution does not happen when same block is run on Solaris.
A Linux workaround is to modify construct to:
$ cat /dev/stdin <<-EOF | sqlplus -l / as sysdba #/dev/stdin
> set echo on termout on
> select systimestamp from dual;
> EOF
SQL*Plus: Release 19.0.0.0.0 - Production on Wed Feb 23 14:38:08 2022
Version 19.11.0.0.0
Copyright (c) 1982, 2020, Oracle. All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.11.0.0.0
SQL> select systimestamp from dual;
SYSTIMESTAMP
---------------------------------------------------------------------------
23-FEB-22 02.38.08.931790 PM -08:00
SQL> Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.11.0.0.0

Resources