Execute sql statement as sys as sysdba - oracle

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

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

SP2-0310: unable to open file "LOGIN.SQL" from Oracle DB 18c in Docker for Windows container

In Docker for Windows I installed an Oracle DB 18c XE Linux Docker container by the books:
Downloaded official sources (from https://github.com/oracle/docker-images)
Created an image from it
Created a container:
docker run --name $containerName -d -p 15210:1521 -e ORACLE_PWD=$dbPassword -v $dbVolume:/opt/oracle/oradata 'oracle/database:18.4.0-xe'
When I open SQL*Plus within the container, everything works fine:
> docker exec -it DevDB sqlplus sys/pwd#//localhost:1521/xe as sysdba
SQL*Plus: Release 18.0.0.0.0 - Production on Fri May 21 19:47:10 2021
Version 18.4.0.0.0
Copyright (c) 1982, 2018, Oracle. All rights reserved.
Connected to:
Oracle Database 18c Express Edition Release 18.0.0.0.0 - Production
Version 18.4.0.0.0
SQL> show con_name
CON_NAME
------------------------------
CDB$ROOT
SQL>
In my Windows host I installed SQLPlus Instant Client. When I run SQL*Plus from there, I get a warning message telling me that "LOGIN.SQL" cannot be opened.
However, I seem to be able to run queries:
> sqlplus sys/pwd#//localhost:15210/xe as sysdba
SQL*Plus: Release 18.0.0.0.0 - Production on Fri May 21 21:34:58 2021
Version 18.5.0.0.0
Copyright (c) 1982, 2018, Oracle. All rights reserved.
Connected to:
Oracle Database 18c Express Edition Release 18.0.0.0.0 - Production
Version 18.4.0.0.0
SP2-0310: unable to open file "LOGIN.SQL"
SQL> show con_name
CON_NAME
------------------------------
CDB$ROOT
SQL>
What is causing this warning message? How can I get rid of it?
After some more testing I now found the answer to my issue:
Apparently, the reported error is a glitch in the 18.5.0.0 release of SQL*Plus.
I just updated SQL*Plus to 19.11.0.0, and the warning message is gone:
> sqlplus sys/pwd#//localhost:15210/xe as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on Fri May 21 21:53:11 2021
Version 19.11.0.0.0
Copyright (c) 1982, 2020, Oracle. All rights reserved.
Connected to:
Oracle Database 18c Express Edition Release 18.0.0.0.0 - Production
Version 18.4.0.0.0
SQL> show con_name
CON_NAME
------------------------------
CDB$ROOT
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>

call oracle procedure in conection string

Is it possible to call an Oracle packageX. procedureY(a, b, c) from the conection string using SqlPlus?
Something like sqlplus user/pass#tns #packageX.ProcedureY(a,b,c) without the need to log into sqlplus and then execute that procedure?
Yes
Jeffreys-Mini:bin thatjeffsmith$ ./sql hr/oracle
SQLcl: Release 19.2.1 Production on Tue Aug 20 18:35:18 2019
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Last Successful login time: Tue Aug 20 2019 18:35:19 -04:00
Connected to:
Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production
Version 18.3.0.0.0
SQL> create or replace procedure do_nothing
2 is
3 begin
4 null;
5 end do_nothing;
6 /
Procedure DO_NOTHING compiled
SQL> exit
Disconnected from Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production
Version 18.3.0.0.0
Jeffreys-Mini:bin thatjeffsmith$ ./sql hr/oracle <<EOF
> exec do_nothing()
> quit
> EOF
SQLcl: Release 19.2.1 Production on Tue Aug 20 18:36:14 2019
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Last Successful login time: Tue Aug 20 2019 18:36:15 -04:00
Connected to:
Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production
Version 18.3.0.0.0
PL/SQL procedure successfully completed.
Disconnected from Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production
Version 18.3.0.0.0
Jeffreys-Mini:bin thatjeffsmith$
In windows you can do it as following:
echo execute packageX.ProcedureY(a,b,c)|user/pass#tns
Cheers!!

oracle instantclient 12c EZCONNECT in Powershell Prompt for password

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?

Resources