0

I need to execute a query by logging into oracle DB using command prompt, Please help me with the query

cd\ && D: && Cd app\Administrator\product\11.1.0\db_1\BIN && (set ORACLE_HOME=D:\app\Administrator\product\11.1.0\db_1) && (sqlplus / as sysdba) 

I am able to log into db using this but i want to execute the below query in the same script

SELECT TO_CHAR (startup_time, 'dd-mon-yyyy hh24:mi:ss') start_time
from V$instance;

When I add this query using &&, it's not working.

jarlh
  • 42,561
  • 8
  • 45
  • 63
NJBrito
  • 1
  • 2
  • Check out this topic: http://stackoverflow.com/questions/638705/how-can-i-issue-a-single-command-from-the-command-line-through-sql-plus – Vadim Landa May 13 '15 at 07:34
  • Unrelated, but: `cd\ && D: && cd ...` can be combined to single statement: `cd /d d:\app\Administrator\product\11.1.0\db_1\BIN` –  May 13 '15 at 08:02

1 Answers1

0

You can @echo the SQL query into SQL*Plus:

cd\ && D: && Cd app\Administrator\product\11.1.0\db_1\BIN && (set ORACLE_HOME=D:\app\Administrator\product\11.1.0\db_1) && (@echo SELECT TO_CHAR (startup_time, 'dd-mon-yyyy hh24:mi:ss') start_time FROM v$instance; | sqlplus / as sysdba) 
Mureinik
  • 297,002
  • 52
  • 306
  • 350
  • Hi mureinik, Thanks for the solution, upon firing this script i got the below error "start_time was unexpected at this time" – NJBrito May 13 '15 at 09:22