Executing sqlplus in windows batch file - URGENT

Hi
Is it possible to run sqlplus.exe thru batch file as follows.
set PATH=%PATH%;C:\oracle\product\10.2.0\client_1\BIN;
host sqlplus userid=test1/test12@testdev
sELECT * FROM CASESTATUS
Thanks
murali

hI
It did not work. I have this question.
1. Do I have to run this opening SQL/PLUS and then submit
@C:\Test\SQL2.bat
2. Or from Windows command run SQL2.Bat
I tried both of them , it did not work. If I try from windows , I am getting SQLPlus connection window at all.
Please help me.
Murali
set PATH=%PATH%;C:\oracle\product\10.2.0\client_1\BIN;
sqlplus userid=test1/test12@testdev
Ok so far but your select needs to be in a file if you want this to be executed.
Put this in, f.ex, run.sql
>>
sELECT * FROM CASESTATUS
>>
then you can use
sqlplus userid=test1/test12@testdev @run.sql <complete path if needed>

Similar Messages

  • Problem in connecting to sqlplus from windows batch file (DOS)

    Hi All,
    We have a new 10g Oracle database installed on windows server. I am trying to write a windows batch file to
    1) Connect to SQLPLUS
    2) Execute a script
    3) Disconnect from SQLPLUS.
    Example File Name:- execsql.bat
    SET ORACLE_SID=CAUT
    SET SCHEMA_IN=%1
    SET PASS=DEV
    SET script=%2
    sqlplus %SCHEMA_IN%/%PASS%@%ORACLE_SID% @%script%
    if %errorlevel% NEQ 0 echo ERROR: %ERRORLEVEL% else echo OK
    Now if i run this bat file like :- execsql.bat DEV script1.sql
    DEV= schema name,
    script1.sql = this file contains select * from dual;
    The code runs fine, but if i change dual to dual1 the sql error's out but not able to catch the error in the batch file.
    Reason why i would like to catch the error is this batch file would be scheduled through Autosys job scheduler and for autosys any exit code >0 is an error. Please help me in rewriting this batch script.
    Thanks
    Sam.

    Hello,
    What if you run this in SQL*Plus before you run the SELECT:
    whenever sqlerror exit failure

  • SQLPLUS from Windows Batch (.bat) Files

    I am executing a SQL script from within a windows batch file using the SQLPLUS command.
    sqlplus %MAX_ORA_USER%/%MAX_ORA_PASSWORD%@%MAX_ORA_DB% @MAIDIOUT_PS_TEST2.sql
    On exit, the SQL returns a code EXIT 0 (Success) or EXIT 2 (Warning).
    I want to be able to capture the value of the exit in the WINDOWS batch file and take some action.
    QUESTION: Does someone have a code example on how to capture hte EXIT value in the Windows Batch file?
    thanks,
    Philip

    Try one of the following constructs:
    IF ERRORLEVEL <x> <command> [ELSE expression]
    IF %ERRORLEVEL% == <x> <command> [ELSE expression]
    GOTO label_%ERRORLEVEL%
    :LABEL_xThe first construct to perform <command> any time the errorlevel is greater or equal to x.
    The second construct will perform <command> anytime the errorlevel equals x.
    The third construct will jump to the specified label with the value of errorlevel appended to it.

  • Call Oracle Stored Procedure with Parameters from Windows Batch File

    Hi,
    I have an oracle procedure that requires two parameters to execute, start date and end date as such:
    CREATE OR REPLACE PROCEDURE insert_orders(
    pSTART_DT IN varchar2
    , pEND_DT IN varchar2
    I want to create a windows batch file to execute the procedure but want to be able to specify the parameters (ie start and end dates) in the batch file as opposed to changing the sql file that the batch file uses to execute the procedure but I don't know what the syntax is. I tried the following but it still doesn't work.
    Sql File: call_insert_orders.sql
    execute insert_orders('&1','&2');
    exit
    Batch File:
    sqlplus username/password @call_insert_orders.sql %01-jan-2010% %01-jan-2011%
    When I execute the batch file, my DOS window still prompts me to enter value 1 so I think it recognizes that there is a variable being used but is not able to fill in the actual value I specify. I'm not an experienced DOS/Windows Batch File person so I'm guessing it's my syntax that's screwed up. There is not a lot of documentation on this subject matter hence my post on this forum. Any helps would be appreciated.
    Thanks

    Hello,
    Just try the same DOS command without all the % sign.
    In MS-DOS, the % at the beginning and at the end of a string are for variables. Which means your batch is looking for a variable called 01-jan-2010 and a variable called 01-jan-2011, but those are the values you want to pass, not the name of variables.
    As they are not defined, nothing is passed to the sqlplus script, and that is why you are prompted for values.
    Hope it will help.
    Regards,
    Sylvie

  • Is there any command in windows batch file similar to the unix grep command

    Hi,
    I have a batch file which will return status of the Database to a file ex: "OPEN". Now I want to read this output file and check for the "OPEN" string from another batch file. any suggestions?. This is similar to "grep" command in unix. I want this to be done in windows batch file.
    This is my actual batch file
    rem -- Description: Check whether the Database is UP
    rem -- Usage:
    rem -- ORACLE_SID is input parameter for the file
    rem --
    rem --start of batch file
    @echo off
    set ORACLE_SID=%1
    echo connect plp/ltd1plp@%1
    echo set cmdsep on
    echo set cmdsep '"'; --"
    echo set term on
    echo spool c:/status_log.log
    echo select status from v$instance;
    echo spool off
    ) | sqlplus /nolog
    rem --end batch file
    Thanks.

    The same link from [google cache|http://209.85.229.132/search?q=cache:EJrm9tgj0a8J:www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/find.mspx+windows+find&cd=1&hl=en&ct=clnk&client=opera]. Also you can use help:
    find /?

  • Is it possible to call a windows batch file from PL/SQL

    Hi gurus,
    Would require your help.Is it possible to call a windows batch file from PL/SQL??If yes can you give an example for the same or any workaround for the same.
    Regards
    Vijay

    Hi!
    Youn need some extproc related entries in you listener.ora and tnsnames.ora file.
    *1. In the listener.ora:*
    Defining the listener process is done in two parts.
    The information contained in each listener differs!!!
    The first part is as follows:
    LISTENER =
      (DESCRIPTION_LIST =
        (DESCRIPTION =
          (ADDRESS = (PROTOCOL = IPC)(KEY = extproc))  <---  *ADD THIS LINE
          (ADDRESS = (PROTOCOL = TCP)(HOST = yourhostname)(PORT = 1521))
      )The seoncd part is as follows:
    SID_LIST_LISTENER =
      (SID_LIST = 
        (SID_DESC =
          (GLOBAL_DBNAME = YOUR_GLOBAL_DBNAME)
          (ORACLE_HOME = c:\oracle\product\10.2.0)  <-- THIS IS YOUR ORACLE_HOME
          (SID_NAME = YOUR_SID)                            <-- SID
        (SID_DESC =                                              <--- ADD THIS LINE
          (SID_NAME = PLSExtProc)                          <--- ADD THIS LINE
          (ORACLE_HOME = c:\oracle\product\10.2.0) <--- ADD THIS LINE AND EDIT TO YOUR ORACLE_HOME
          (PROGRAM = extproc)                                <--- ADD THIS LINE
          (ENV = "EXTPROC_DLLS=ANY")                  <--- ADD THIS LINE
        )                                                                <--- ADD THIS LINE
      )*2. In the tnsnames.ora you need to add the following entry:*
    *(The KEY value entered must be match to the KEY value entered int the listener.ora file!)*
    EXTPROC_CONNECTION_DATA =
      (DESCRIPTION =
        (ADDRESS_LIST =
          (ADDRESS = (PROTOCOL = IPC)(KEY = extproc))
        (CONNECT_DATA =
          (SID = PLSExtProc)
          (PRESENTATION = RO)
      )Finally you need to restart your listiner. After restarting there will be a service called "PLSExtProc" in your listener.
    This are only examples for extproc configuration, your tnsnames.ora and listener.ora can be differs.
    FIRST MAKE MAKE A BACKUP OF YOUR ORIGINAL tnsnames.ora AND listener.ora FILES
    For more information please check metalink note 68061.1 "EXTPROC: Creating External Procedures on Windows NT"
    Bestr Regards
    Norbert

  • Is it possible to call a windows batch file from PL/SQL block ??

    Hi gurus,
    Would require your help.Is it possible to call a windows batch file from PL/SQL block ??If yes can you give an example for the same or any workaround for the same.
    Regards
    Vijay

    You didn't specify a database version, but if you are 10g or higher, it's quite straightforward using an external job type in DBMS_SCHEDULER. Funnily enough i'm looking at something similar myself at the moment.
    Useful guide to some of the issues here Guide to External Jobs on 10g with dbms_scheduler e.g. scripts,batch files

  • Maxl within Windows Batch File

    Hello,
       I am trying to schedule an Automatic Essbase Archiving command . Function is to Disable connects , Archive , Unarchive and Enable connects . I know the Maxl commands which perform this action but just wanted to make sure how to portray this within a Windows Batch file.
    Within the Batch file , abc.bat can I insert those commands . To enter the shell we need essmsh command , but I didnt wanted to get into decrypting , encrypting the ID etc to do that . So is there a way to get it done within the Windows batch file ?
    Thanks !!

    Yes its Straight forward case ,create a batch file which call the maxl script.The batch file should contain the user id and password of Essbase and the maxl script should contain the parameters of Essbase archiving
    The content of batch file for Essbase archiving process
    echo off
    set ESSUSER=admin
    Set ESSPWD=Password
    set ESSSERVER=localhost
    set ESSAPP=Sample
    set ESSDB=Basic
    SET ESSBASE SERVER PATH=D:\Hyperion\Middleware\EPMSystem11R1\products\Essbase\EssbaseServer
    set MaxlScript=D:\Hyperion\Middleware\user_projects\epmsystem1\Essbaseserver\essbaseserver1\bin
    essmsh "D:\Archieve.mxl" %ESSUSER% %ESSPWD% %ESSSERVER%
    ===================================================================================================
    Maxlscript Content for Archieving
    spool on to "D:/bck.log";
    set timestamp on;
    login $ESSUSER $ESSPWD on $ESSSERVER;
    display session all;
    alter system kill request all;
    alter system logout session all force;
    export database $essApp.$essDB all data to server data_file 'd:\alldata.txt';
    alter database $essApp.$essDB force archive to file "D:/sample.arc";
    alter database $essApp.$essDB end archive;
    spool off;
    logout;
    exit;
    Similarly can you create batch files for Cube restoration .I hope the above example helps you
    Thanks,
    Sreekumar Hariharan

  • Where windows batch file which log off windows lies ?

    where windows batch file which log off windows lies ?
    to which me can call from java code to log off my pc?

    You should use a brute-force algorithm on the on/off switch on your pc. I suggest a rate of 30 hits per minute.

  • Where windows batch file lies which log off windows ?

    where windows batch file lies which log off windows ? wana log off my pc from java code

    grc.com has a program (very small) that does it. The program is called "wizmo" and is written in Assembly.
    If you are using Windows NT/2000/XP you can get a program in MS Windows Resource Kit called "shutdown.exe" but the program does only the shutdown job. You must manually turn the machine off.

  • How to execute sqlplus command in bat file ?

    Hello
    I have a simple script file that looks like this:
    "sqlplus admin/admin as sysdba
    shutdown immediate"
    But.. when i start this file.bat my system logs but do not make any script. Sqlplus just waiting for command, and when i write "exit" i logout from sqlplus, and then system execute next command, that is "shutdown immediate" but beyond sqlplus (so my base is still working). Is it at all possible to log on and execute commands from file.bat or some other way ?
    I'm using oracle 11g, windows 7x64
    Regards and thx for help
    Edited by: 879529 on 2011-11-27 04:52

    969970 wrote:
    Thank you that worked for me.But I fear you don't really understand WHY it worked, and WHY your first attempts did not work.
    So let me explain
    Given this .bat file
    sqlplus / as sysdba
    shutdown immediateWhat happens when you execute the file? The windows command processor reads the file line by line and processes the command on each line. What is the first lilne?
    sqlplus / as sysdbaSo what would you expect to happen when Windows processes that line? Remember, it's exactly as if you had entered that command yourself at the command prompt .... Answer: The OS locates an executable file named 'sqlplus', loads it into memory and passes control to it, along with a pointer to the rest of the command line ('/ as sysdba'). At that point, the executable sqlplus has control and will do whatever it wants with the command line it was passed ('/ as sysdba') and then waits for user input for more commands, including an 'exit' command. Where are those commands going to come from? They are NOT going to come from the next line in the bat file. They can't. The command processor that is running the bat file is still waiting for sqlplus to finish and return control. So you are stuck. The only way out is to break out of sqlplus with a 'ctl-break'. Once that happens, the command processor moves on to the next line in the bat file:
    shutdown immediateSo now the os tries to locate an executable file named 'shutdown' .... you probably don't have an executable by that name (let's hope not!) so you then get an error message from the OS informing you that
    'shutdown' is not recognized as an internal or external command,
    operable program or batch file.Now, if you were using a real OS, you could achieve what you wanted by using input redirection, but unfortunately, Windows just has a toy for a command processor.

  • How to check Oracle DB Status from Windows batch file

    Hi,
    I need a script which can be used to check the Oracle Database Status from windows command batch file.
    Thanks,
    Kishore

    Hi Virendra,
    I have followed the steps mentioned in ur reply, But couldn't get the output.
    I am getting the below error
    C:\>db_utility.bat PLPDEV
    ERROR:
    ORA-12560: TNS:protocol adapter error
    SP2-0306: Invalid option.
    Usage: CONN[ECT] [logon] [AS {SYSDBA|SYSOPER}]
    where <logon> ::= <username>[<password>][@<connect_string>] | /
    SP2-0306: Invalid option.
    Usage: CONN[ECT] [logon] [AS {SYSDBA|SYSOPER}]
    where <logon> ::= <username>[<password>][@<connect_string>] | /
    SP2-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus
    C:\>
    Below is my bat file
    @echo off
    set ORACLE_SID=%1
    echo sys/ltd1_plp as sysdba
    echo set cmdsep on
    echo set cmdsep '"'; --"
    echo set term on
    echo "select status from v$instance;"
    ) | sqlplus -s
    Thanks

  • What is the default program to run windows batch files?

    I am working on windows 7 and I found that "notepad" was set as the default program for opening my .bat files. when I try to execute the batch file by double clicking, it is opened by notepad.
    I have tried setting cmd.exe as the default program, it just opens the command prompt.
    What is the default program I should set for executing .bat files?
    I hav also tried using assoc .bat = batfile. The batch file runs fine from command prompt.

    This is not a scripting question.  It is a break/fix issue.  Contact you support person or Admin for assistance fixing this.
    http://www.sevenforums.com/general-discussion/53877-bat-files-open-notepad-instead-running-help.html
    ¯\_(ツ)_/¯

  • Executable-Job to call batch-file

    Dear NG!
    I'm currently using Oracle 10.1.0.4 on a MS Windows Server 2003 and
    I've got some problems concerning EXECUTABLE-Jobs in DBMS_SCHEDULER.
    I just want to PIPE OUT the results of my Batch-Execution in a LOG-File,
    but ORACLE just returns an error code.
    Here's my example:
    the Batch-File "TEST.bat" contains:
    dir c:\temp >c:\temp\content.log
    the SCHEDULER-Job to run in PL/SQL:
    BEGIN
    DBMS_SCHEDULER.CREATE_JOB (
    JOB_NAME =>'TEST1',
    JOB_TYPE =>'executable',
    JOB_ACTION =>'c:\temp\TEST.bat',
    ENABLED => TRUE,
    AUTO_DROP => TRUE
    COMMIT;
    DBMS_SCHEDULER.RUN_JOB('TEST1');
    END;
    the LOG-Message:
    ORA-27369: Job vom Typ EXECUTABLE nicht erfolgreich mit Exit-Code: Unzul¿ige Funktion.
    I also tried the following JOB_ACTION-Parameter:
    - 'c:\windows\system32\cmd.exe /q /c c:\temp\TEST.bat'
    or
    - 'c:\windows\system32\cmd.exe /q /c c:\temp\TEST.bat >Nul'
    or
    - 'dir c:\temp >c:\temp\content.log'
    or
    - 'c:\windows\system32\cmd.exe /c /q dir c:\temp >c:\temp\content.log'
    ...but I had no success.
    I already read the posts in the forums about that but I did not found any solution.
    Could someone please tell me where my mistake is?
    A rapid response would be appreciated!
    Thanks in advance!
    Dirk

    You may be hitting bug 3663347 - WIN32/SCHEDULER: EXECUTABLE JOB FAILS WITH 'ORA-27369: THE HANDLE IS INVALID', which should be fixed by Patch 4287619.

  • In windows batch file,how to check if connection to db is successful or not

    I want to do some operations in batch file. So i use command "sqlplus usr/pwd@con @operation.sql" to in the batch file. But how can i check if i connect successfully? The %ErrorLevel% is always 0

    Change your batch script as follows:
    (P.S. You could prompt for the values in the batch file as well)
    file: test.bat
    @echo off
    sqlplus /nolog @operation.sql <username> <password> <alias>file: test.sql
    define username='&1'
    define password='&2'
    define alias='&3'
    whenever sqlerror exit failure;
    connect &username/&password@&alias
    whenever sqlerror continue;Now you should get a failure message as a result of:
    whenever sqlerror exit failure;you can also exit with a specific value
    whenever sqlerror exit -5;

Maybe you are looking for