SQL*Plus issues with connection to DB from Command Prompt - oracle

I am on SQL*Plus: Release 21.0.0.0.0, on a Windows machine.
In the command prompt, when I do
C:\users\TOMMY> sqlplus /nolog
I see this
SQL>
Here I connect to the Database using a connection string(EZ Connect format)
With Credentials,
username -> dddd
pwd -> wefm#vrev
host -> local
port -> 15210
ServiceName -> abcd.xysp.gthe.com
SQL> connect dddd/"wefm#vrev"#local:15210/abcd.xysp.gthe.com
And I see Output(after a few seconds),
Connected.
My issue begins when I decide to connect from Windows directly with sqlplus. Mentioned below
C:\users\TOMMY> sqlplus -S
dddd/"wefm#vrev"#local:15210/abcd.xysp.gthe.com
Results in an error, I am baffled. What am I missing
ERROR: ORA-12154: TNS:could not resolve the connect identifier
specified
I have also tried putting the connection string in single quotes (').
When I do that I get this whole thing printed out, which I assume is indicative of me passing the wrong args.
SQL*Plus: Release 21.0.0.0.0 - Production Version 21.3.0.0.0
Copyright (c) 1982, 2021, Oracle. All rights reserved.
Use SQLPlus to execute SQL, PL/SQL and SQLPlus 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 [ [] [{logon | /nolog}] [] ]
is: [-C ] [-F] [-L] [-M ""]
[-NOLOGINTIME]
[-R ] [-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
-F This option improves performance in general. It changes
the default values settings.
See SQL*Plus User's Guide for the detailed settings.
-L Attempts to log on just once, instead of
prompting 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.
is: {[/][#<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>] |
[[[protocol:]//]host1{,host12}[:port1]{,host2:port2}[/service_name]
[:server][/instance name][?[parameter name=value]
{&parameter name=value}]]]
<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 username/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 username/mypassword#Host/ORCL
The /NOLOG option starts SQL*Plus without connecting to a
database.
The EDITION specifies the value for Session Edition.
is: #|[.] [ ...]
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 SQLPlus 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 SQLPlus commands.
Refer to the SQL*Plus User's Guide and Reference for more information.
I would like a solution that only involves using a connection string. I don't want to be using tns_ora file
Also without any manual intervention. I don't want to separately enter the password after I put in 'username#connect-identifier'.
Please ignore security related issues of passing in the password visibly in the cmd prompt. That is fine with me.

Solution powershell script test-connect2.ps1:
$username = "demin"
$password = '"test#test"'
$connect_string ="10.241.33.71:1521/DEV"
$log_file = "log.txt"
$list_scripts = "connect $username/$password#$connect_string"
$list_scripts = $list_scripts + "
select 1,sysdate from dual;
#file1.sql
#file2.sql"
$list_scripts | sqlplus -s /nolog >>$log_file
Run script:
C:\instantclient_21_3>powershell .\test-connect2.ps1
output log.txt
1 SYSDATE
---------- ---------
1 27-MAY-22
2 SYSDATE
---------- ---------
2 27-MAY-22
3 SYSDATE
---------- ---------
3 27-MAY-22
SQL*Plus: Release 11.2.0.4.0 Production on Fri May 27 06:34:41 2022
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
SQL> alter user DEMIN identified by "test#test";
User altered.
SQL> exit
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
C:\>sqlplus demin/"test#test"#dev19
SQL*Plus: Release 11.2.0.4.0 Production on Fri May 27 06:35:14 2022
Copyright (c) 1982, 2013, Oracle. All rights reserved.
ERROR:ORA-12154: TNS:could not resolve the connect identifier specified
Enter user-name:
C:\>sqlplus demin/\"test#test\"#dev19
SQL*Plus: Release 11.2.0.4.0 Production on Fri May 27 06:35:23 2022
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
SQL> show user
USER is "DEMIN"
SQL>
C:\app\product\18.0.0\dbhomeXE\bin>sqlplus demin/\"test#test\"#dev19
SQL*Plus: Release 18.0.0.0.0 - Production on Fri May 27 10:28:18 2022
Version 18.4.0.0.0
Copyright (c) 1982, 2018, Oracle. All rights reserved.
Last Successful login time: Fri May 27 2022 06:35:29 +03:00
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.12.0.0.0
SQL>
C:\instantclient_19_15>sqlplus demin/\"test#test\"#dev19
SQL*Plus: Release 19.0.0.0.0 - Production on Fri May 27 11:23:35 2022
Version 19.15.0.0.0
Copyright (c) 1982, 2021, Oracle. All rights reserved.
Last Successful login time: Fri May 27 2022 10:31:49 +03:00
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.12.0.0.0
SQL>
C:\instantclient_21_3>sqlplus demin/\"test#test\"#dev19
SQL*Plus: Release 21.0.0.0.0 - Production on Fri May 27 11:18:08 2022
Version 21.3.0.0.0
Copyright (c) 1982, 2021, Oracle. All rights reserved.
ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified

Related

How to Redirect Input to SQL*Plus without Exiting using Windows PowerShell

Using Windows PowerShell, how do I redirect input into sqlplus (non-interactive stdin mode) such that once the redirected input is complete sqlplus is left open in interactive stdin mode without SQL*Plus exiting?
It appears as though the redirected input is issuing an implicit exit which SQL*Plus is processing.
Using Oracle 19c Enterprise Edition, Oracle InstantClient 19c 64-bit, Windows PowerShell Desktop 5.1.19041.1320, Microsoft Windows 10.0 build 19042.
Thank you in advance.
dev.sql
set echo on
set serveroutput on
exec dbms_output.put_line('hello world');
No redirection executes start script dev.sql and does not exit (notice the SQL> prompt as the last line instead of PS C:\Users\my>).
PS C:\Users\my> sqlplus my_username/my_password#"my_host:my_port/my_service" "#dev.sql"
SQL*Plus: Release 19.0.0.0.0 - Production on Tue Feb 15 14:44:48 2022
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Last Successful login time: Tue Feb 15 2022 14:40:03 -05:00
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.14.0.0.0
SQL> set serveroutput on
SQL> exec dbms_output.put_line('hello world');
hello world
PL/SQL procedure successfully completed.
SQL>
However, when redirecting the input, then SQL*Plus automatically exits (notice the PS C:\Users\my> prompt as the last line instead of SQL>). No matter how I redirect the input into sqlplus, SQL*Plus automatically exits.
Redirection with Get-Content.
PS C:\Users\my> Get-Content dev14.sql | sqlplus my_username/my_password#"my_host:my_port/my_service"
SQL*Plus: Release 19.0.0.0.0 - Production on Tue Feb 15 14:48:42 2022
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Last Successful login time: Tue Feb 15 2022 14:44:49 -05:00
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.14.0.0.0
SQL> SQL> SQL> hello world
PL/SQL procedure successfully completed.
SQL> Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.14.0.0.0
PS C:\Users\my>
Redirection with here-string.
PS C:\Users\my> #"
>> set echo on
>> set serveroutput on
>> exec dbms_output.put_line('hello world');
>> "# | sqlplus my_username/my_password#"my_host:my_port/my_service"
SQL*Plus: Release 19.0.0.0.0 - Production on Tue Feb 15 14:50:14 2022
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Last Successful login time: Tue Feb 15 2022 14:48:44 -05:00
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.14.0.0.0
SQL> SQL> SQL> hello world
PL/SQL procedure successfully completed.
SQL> Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.14.0.0.0
PS C:\Users\my>
Single line redirection.
PS C:\Users\my> "select * from dual;" | sqlplus my_username/my_password#"my_host:my_port/my_service"
SQL*Plus: Release 19.0.0.0.0 - Production on Tue Feb 15 15:03:10 2022
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Last Successful login time: Tue Feb 15 2022 15:00:34 -05:00
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.14.0.0.0
SQL>
D
-
X
SQL> Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.14.0.0.0
PS C:\Users\my>
Redirect using Start-Process.
PS C:\Users\my> Start-Process sqlplus my_username/my_password#"my_host:my_port/my_service" -RedirectStandardInput dev.sql -NoNewWindow -Wait
SQL*Plus: Release 19.0.0.0.0 - Production on Tue Feb 15 15:06:20 2022
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Last Successful login time: Tue Feb 15 2022 15:06:07 -05:00
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.14.0.0.0
SQL> SQL> SQL> hello world
PL/SQL procedure successfully completed.
SQL> Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.14.0.0.0
PS C:\Users\my>
Redirecting using batch, still causes SQL*Plus to exit.
dev.bat
(
echo set echo on
echo set serveroutput on
echo exec dbms_output.put_line('hello world'^^^);
) | sqlplus my_username/my_password#"my_host:my_port/my_service"
PS C:\Users\my> c:dev.bat
C:\Users\my>(
echo set echo on
echo set serveroutput on
echo exec dbms_output.put_line('hello world'^);
) | sqlplus my_username/my_password#"my_host:my_port/my_service"
SQL*Plus: Release 19.0.0.0.0 - Production on Tue Feb 15 15:57:51 2022
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Last Successful login time: Tue Feb 15 2022 15:57:38 -05:00
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.14.0.0.0
SQL> SQL> SQL> hello world
PL/SQL procedure successfully completed.
SQL> Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.14.0.0.0
PS C:\Users\my>
Note: I tried using -noexit but that is an argument to executing powershell itself not sqlplus.
It is like sqlplus says "okay, no more stdin, I'm done". Maybe there is a way to direct stdin back to they keyboard once pipped input reaches end-of-file, so sqlplus is left waiting for the next keyboard input?
Note: It is also odd how we do not see the set serveroutput on getting echoed.
Thank you.
Sqlplus automatically exits when its' input pipe (stdin) is closed. So the only option is to do not close pipe: you can write a program that starts sqlplus and feeds it's stdin and closes it only when you want.
I don't know why do you want to leave it open in non-interactive mode.
For me it's much better to pipe to file and then execute it.
Don't know will it help you, but I have a couple of workarounds how to leave it open for some time: use host command. For example the following command will leave sqlplus opened for 15 seconds:
"host powershell Start-Sleep -s 15" | sqlplus user/pass#//host:port/service
Note that you can't do anything with interactive stdin within it, like
"host timeout /t 10" | sqlplus user/pass#//host:port/service
because
SQL> ERROR: Input redirection is not supported, exiting the process immediately.

Oracle sqlplus with sys as sysdba is failing with ORA-01017: invalid username/password; logon denied

Oracle sys user database connection with ORACLE_SID is not working. dev is my ORACLE_SID .
sqlplus sys/manager#dev as sysdba
SQL*Plus: Release 12.1.0.2.0 Production on Thu Nov 25 01:25:33 2021
Copyright (c) 1982, 2014, Oracle. All rights reserved.
ERROR:
ORA-01017: invalid username/password; logon denied
But without ORACLE_SID connection is working
sqlplus sys/manager as sysdba
SQL*Plus: Release 12.1.0.2.0 Production on Thu Nov 25 01:34:05 2021
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SQL>
Looks like this connection is using OS authentication. Because if I provide wrong password for sys user still connection works.
Any help why with ORACLE_SID sys user connection is not working?
In my database sec_case_sensitive_logon parameter is set to false.
SQL> show parameter sec_case_sensitive_logon
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
sec_case_sensitive_logon boolean FALSE
Following was the root cause:
remote_login_passwordfile parameter was set to EXCLUSIVE
SQL> show parameter remote_login_passwordfile
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
remote_login_passwordfile string EXCLUSIVE
REMOTE_LOGIN_PASSWORDFILE specifies whether Oracle checks for a password file.
For me password file was missing.
Created password file
orapwd file=$ORACLE_HOME/dbs/orapw<sid> password=<password> force=y ignorecase=n
Bounce database.
Then Oracle sys user database connection with ORACLE_SID is working.
sqlplus sys/manager#dev as sysdba
SQL*Plus: Release 12.1.0.2.0 Production on Thu Nov 25 03:35:47 2021
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

localhost:5500/em Username/Password error -------Oracle18c Express Edition

I followed a YouTube Video, and installed Oracle 18c Express Edition, gave password for localhost during installation. After successful installation I tried to access https://localhost:5500/em but couldn't login because of username/password incorrect issue. I tried usernames like: sys and sysdba but failed.
It's not at all clear what you did. You said "gave password for localhost during installation. ", but 'localhost' is not an account and so doesn't have a password. 'localhost', is a network name, used to indicate where network requests are to be routed. Specifically, 'localhost' is the network name that equates to ip address 127.0.0.1, which is the local loopback address.
If you cannot remember the password you created for a database account, such as SYS or SYSTEM, you can log on locally as SYSDBA and change what you need. From a command prompt on the database server:
oracle:cdb$ sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on Thu Jul 1 09:23:37 2021
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
SQL> alter user sys identified by "halftrack";
User altered.
SQL>

What to do whenever I opens my browser it shows "ORACLE DATABASE 10g EXPRESS EDITION LICENSE AGREEMENT"?

None of my browser are working whenever I query in browser I get the message "ORACLE DATABASE 10g EXPRESS EDITION LICENSE AGREEMENT". What to do?
I too faced same issue and fixed the issue by following these steps. Please have a try.
From Start | Run open a command window. Assuming your environmental variables are set correctly start with the following:
C:\>sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on Tue Aug 26 10:40:44 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> connect
Enter user-name: system
Enter password: <enter password if will not be visible>
Connected.
SQL> Exec DBMS_XDB.SETHTTPPORT(3010); [Assuming you want to have HTTP going to this port]
PL/SQL procedure successfully completed.
SQL>quit
Now restart the PC and check.

Connect to Oracle as SYSDBA using OCI or SQL*Plus, from client machine

I'm using Instant-Client 12.1.0.2.0, connecting to a 12.1.0.1.0 (Linux) server, in Multi-Tenant configuration.
Using either:
SQL*Plus
OCILogon2
OCIServerAttach + OCISessionBegin(OCI_RDBMS credentials, OCI_DEFAULT mode)
I can connect (using EZCONNECT, no environment variables at all) from a client machine to a PDB on the server, using SYSTEM. E.g.
c:\>sqlplus system#'//host/pdb12c_1.domain.net'
SQL*Plus: Release 12.1.0.2.0 Production on Tue Oct 20 11:14:10 2015
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Enter password:
Last Successful login time: Tue Oct 20 2015 11:10:10 +02:00
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SQL> quit
But as soon as I add as SYSDBA to the command line, it fails:
c:\>sqlplus system#'//host/pdb12c_1.domain.net' as SYSDBA
SQL*Plus: Release 12.1.0.2.0 Production on Tue Oct 20 11:14:22 2015
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Enter password:
ERROR:
ORA-01017: invalid username/password; logon denied
I've modified my OCI application to use OCI_SYSDBA as the mode to OCISessionBegin, and it fails the same way. I've tried SYSOPER with both SQL*Plus and my OCI client app, and it also fails the same way.
What am I missing? What kind of restriction are placed on connection that want to gain SYSDBA? Is this mode impossible from a client machine? Or is that because I connect to a PDB instead of the CDB?
I'd appreciate some insights. Thanks.
PS: yes, I double and triple checked I typed the password in correctly
c:>sqlplus system#'//host/pdb12c_1.domain.net' as SYSDBA
You are using SYSTEM user which is incorrect. You need to use SYS.
For example,
C:\Users\lkb>sqlplus sys#pdborcl as sysdba
SQL*Plus: Release 12.1.0.1.0 Production on Tue Oct 20 15:11:25 2015
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Enter password:
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SQL>

Resources