oracle instantclient 12c EZCONNECT in Powershell Prompt for password - oracle

I have installed instantclient 12c x86 on Windows 8.1
I am able to connect from cmd.exe:
C:\Users\vagrant>sqlplus user#\"hostname:1521/SERVICE_NAME\"
SQL*Plus: Release 12.1.0.2.0 Production on Thu Dec 3 06:22:31 2015
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Enter password:
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management,
OLAP,
Data Mining and Real Application Testing options
SQL>
Now when I try the same from Powershell:
I want to be prompted for password. It does not work.
PS C:\Users\vagrant> sqlplus user#\"hostname:1521/SERVICE_NAME\"
SQL*Plus: Release 12.1.0.2.0 Production on Thu Dec 3 06:30:12 2015
Copyright (c) 1982, 2014, Oracle. All rights reserved.
ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified
Enter user-name:
Here I provide my password and it works
PS C:\Users\vagrant>sqlplus user/password#hostname:1521/SERVICE_NAME
SQL*Plus: Release 12.1.0.2.0 Production on Thu Dec 3 06:24:48 2015
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
SQL>
What is the correct syntax for being prompted for password logging in with sqlplus from Powershell?

Related

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

Get the Oracle Version using CMD

Is there is any command to find my installed oracle version from windows command prompt. (just like java -version..)
You need to locate ORACLE_HOME directory, to set it as environment variable and then to run opatch:
set ORACLE_HOME=...
"ORACLE_HOME"\OPatch\opatch lspatches
This command lists the installed patches with the Oracle major version.
You can use the below to get the database version by navigating to the ORACLE_HOME directory
$ORACLE_HOME\OPatch\opatch lsinventory | find "Oracle Database"
Well, that depends on what you really have.
If you have installed Oracle onto your PC (such as my 11gXE), then you could try sqlplus -v:
c:\Temp>sqlplus -v
SQL*Plus: Release 11.2.0.2.0 Production
11.2.0.2.0; is that really so?
c:\Temp>sqlplus scott/tiger
SQL*Plus: Release 11.2.0.2.0 Production on Sri Svi 6 07:40:29 2020
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
SQL>
Yes, it is. I use SQL*Plus 11.2.0.2.0 which connects me to 11.2.0.2.0 database.
However, if I don't have Oracle installed on my PC but it is somewhere on database server and I access it via network, then it won't work because it'll display SQL*Plus (i.e. client installed on my PC), not database version. Besides, I can have several clients installed, so it depends on which sqlplus executable I ran.
Database version - in such a case - can't be retrieved from operating system command prompt only (at least, I don't know how to do it). You can obtain it by connecting to the database itself, e.g.
Client version:
M:\>sqlplus -v
SQL*Plus: Release 11.2.0.1.0 Production
ORCL database version is 11.2.0.4.0
M:\>sqlplus scott/tiger#orcl
SQL*Plus: Release 11.2.0.1.0 Production on Sri Svi 6 08:12:27 2020
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
ORCL2 database version is 10.2.0.5.0:
M:\>sqlplus scott/tiger#orcl2
SQL*Plus: Release 11.2.0.1.0 Production on Sri Svi 6 08:13:42 2020
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, Real Application Clusters, Data Mining and Real Application Testing options
SQL>
When you're in SQL*Plus, query v$version, e.g.
SQL> select * From v$version where rownum = 1;
BANNER CON_ID
-------------------------------------------------------------------------------- ----------
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production 0
SQL>
which shows that I'm currently connected to 12.2.0.1.0.
This code allows you to display only the version of the database.
#echo off
set user_name=scott
set password=tiger
set net_service_name=edcu
set sql=select version from PRODUCT_COMPONENT_VERSION where rownum=1;
(echo conn %user_name%/%password%#%net_service_name%
echo set heading off
echo %sql%
echo exit) |sqlplus -s /nolog
For example output
D:\upwork\stackoverflow\get_version_oracle>get_oracle_version.bat
11.2.0.3.0

Execute sql statement as sys as sysdba

I have a sql statement executed in a script which connects to sqlplus and execute some GRANTS statements. In the bash script the instruction is something like:
sqlplus sys as sysdba #script.sql
but I need to add the password. How can I do in a single line ?
I tried:
sqlplus "sys as sysdba"/password #script.sql
or without " but it does not work.
Thanks
Example 1
oracle#esmd:~> sqlplus / as sysdba #ulcase1.sql
SQL*Plus: Release 11.2.0.3.0 Production on Fri Feb 21 12:07:50 2020
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Release 11.2.0.3.0 - 64bit Production
Disconnected from Oracle Database 11g Release 11.2.0.3.0 - 64bit Production
oracle#esmd:~>
Example 2
oracle#esmd:~> sqlplus sys/password as sysdba #ulcase1.sql
SQL*Plus: Release 11.2.0.3.0 Production on Fri Feb 21 12:08:44 2020
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Release 11.2.0.3.0 - 64bit Production
Disconnected from Oracle Database 11g Release 11.2.0.3.0 - 64bit Production
oracle#esmd:~>
Example 3
oracle#esmd:~> sqlplus sys/password#esmd as sysdba #ulcase1.sql
SQL*Plus: Release 11.2.0.3.0 Production on Fri Feb 21 12:14:49 2020
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Release 11.2.0.3.0 - 64bit Production
Disconnected from Oracle Database 11g Release 11.2.0.3.0 - 64bit Production
oracle#esmd:~>
You can execute it on this way:
sqlplus sys/password as sysdba #script.sql

Changing Oracle 11g SYSTEM Password

I want to change my SYSTEM password in 11G Oracle.
When Entered Command in Cmd
C:\Users\ranvi>sqlplus "/as sysdba"
SQL*Plus: Release 11.2.0.1.0 Production on Tue Oct 8 20:59:06 2019
Copyright (c) 1982, 2010, Oracle. All rights reserved.
ERROR:
ORA-01031: insufficient privileges
Enter user-name:
enter image description here
This is how I do it:
c:\Temp>sqlplus system
SQL*Plus: Release 11.2.0.2.0 Production on Uto Lis 8 20:38:05 2019
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Enter password:
Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
SQL>
System doesn't have to connect as sysdba (but sys does):
c:\Temp>sqlplus sys
SQL*Plus: Release 11.2.0.2.0 Production on Uto Lis 8 20:38:49 2019
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Enter password:
ERROR:
ORA-28009: connection as SYS should be as SYSDBA or SYSOPER
Enter user-name:
So:
c:\Temp>sqlplus sys as sysdba
SQL*Plus: Release 11.2.0.2.0 Production on Uto Lis 8 20:39:17 2019
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Enter password:
Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
SQL>

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