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.

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

  • Setting Oracle environment variable using batch (.bat) file in windows

    Hi,
    Oracle 9i db
    Windows OS
    I am in process to create the database (Considered that Oracle9i software is already installed) by running one batch file which consist of all the scripts for the database creation.
    But i also want to set the environment variables at MyComputer(right click)>properties>advance>environment, permenently by running the batch (.bat) file
    ORACLE_HOME
    ORACLE_BASE
    ORACLE_SID
    So, how can it be done ?
    With Regards

    Hi,
    *@echo off*
    set ORACLE_SID=iprsdb
    set ORACLE_BASE=C:\oracle
    set ORACLE_HOME=C:\oracle\ora92     
    call C:\install_bkp\test_env_var.bat
    echo Test Successfull.
    Above mentioned is the code written in the batch (.bat) file
    In that i have also called another .bat file which test the env. variable values which is as below:
    c:\>test_env.bat
    ===================
    Testing oracle sid
    ===================
    iprsdb
    =====================
    Testing oracle base
    ===================
    C:\oracle
    =====================
    Testing oracle home
    =====================
    C:\oracle\ora92
    Test Successfull.
    But when i checked at MyComputer(right click)>properties>advance>environment variables
    there, I saw none of the entries from the above, why so ?
    how to set env. variables permanently using the DOS commands. ?
    With Regards

  • 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>

  • 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

  • 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

  • How to call SQL job step by step from windows batch file

    Hi ,
    I have a SQL agent job [POC_IOD_RunPkgJob]  which is being called from bat file with below command.
    Could you please tell me how to call only one step of this job, what command I need to mention in the batch file.
    SQLCMD -Sabcwi\SQLI01,51565 -E -Q"exec msdb.dbo.sp_start_job [POC_IOD_RunPkgJob]"

    Hi RameshDravid,
    Regarding your description,though not aware of what is the purposed to call only one step of that job, the below sample can somewhat help to achieve your requirement.
    --find the job steps
    SELECT
    steps.step_id,steps.step_name,steps.subsystem,steps.command
    FROM msdb.dbo.sysjobsteps steps
    JOIN msdb.dbo.sysjobs jobs
    ON steps.job_id = jobs.job_id
    WHERE jobs.name = 'youJobName'
    --find the command runs in that step, usually that is some command exec stored procedure
    SQLCMD -Sabcwi\SQLI01,51565 -E -Q"exec stored procedure found in the above query"
    If you have any question, feel free to let me know
    Eric Zhang
    TechNet Community Support

  • Windows and bat files

    Hi
    I've made some bat files to compile java sources and run the program.
    After the termination of the program i want the bat file to stop and let me see the messages on console but it closes automatically.
    I tried put pause at the end of the bat file but it does not work.
    Just after finish the java program the console exits and never executes the pause command.
    Why ?
    how Can I do ?

    I tried this one windows XP and it worked fine:
    Test program: public class Test {
        public static void main(String[] args) {
         System.out.println("Test program running");
         System.exit(1);
    }Batch file (called runtest.bat): java -classpath c:\temp Test
    pauseThen I created a shortcut to "runtest.bat". It opened a console window and paused with this output: C:\temp>java -classpath c:\temp Test
    Test program running
    C:\temp>pause
    Press any key to continue . . .How are you running the batch file? Is it from a shortcut on Windows, or from a third party tool, like an editor?
    What is the command line you're using to run the batch file?
    Tim

  • Windows 7 & bat files & login script

    We have Netware 6.5 SP8.
    How can I run a bat file from the login script so that it will "Run as Administrator" on the Windows 7 workstations?
    Thanks...

    Actually this is more of a MS/Win7 batch processing question.
    In short, you can't assign Admin rights to batch files, only to EXE or
    shortcuts.
    Therefor, try creating a shortcut to the batch file.
    Right-click on the shortcut -> Properties -> Shortcut tab -> Advanced.
    Click "Run as administrator".
    Test locally.
    Now you can try passing that shortcut to the Login Script command
    handler - something like:
    #cmd /c start [shortcut]
    or
    #%<comspec> /c start [shortcut]
    Note, this is all untested and unsupported.
    Good luck
    Wolfgang
    On 28.06.2012 20:46, ncharleyhog wrote:
    >
    > We have Netware 6.5 SP8.
    >
    > How can I run a bat file from the login script so that it will "Run as
    > Administrator" on the Windows 7 workstations?
    >
    > Thanks...
    >
    >

  • Check oracle db status from windows batch file?

    Hi
    any body have a batch to do that
    i want to check connecting , not just the service
    thanks very much

    I have a process in batch files (dos programming )which prepare some files then call oracle store procedures, i need to have a way to check >if the database is up(open) before i start my processingHow can I tell if the light will light without turning on the switch?
    While it can be done, the simplest & easiest way is to try to connect for real & trap any error which may result from it not working.

  • Capturing log files from multiple .ps1 scripts called from within a .bat file

    I am trying to invoke multiple instances of a powershell script and capture individual log files from each of them. I can start the multiple instances by calling 'start powershell' several times, but am unable to capture logging. If I use 'call powershell'
    I can capture the log files, but the batch file won't continue until that current 'call powershell' has completed.
    ie.  within Test.bat
    start powershell . \Automation.ps1 %1 %2 %3 %4 %5 %6 > a.log 2>&1
    timeout /t 60
    start powershell . \Automation.ps1 %1 %2 %3 %4 %5 %6 > b.log 2>&1
    timeout /t 60
    start powershell . \Automation.ps1 %1 %2 %3 %4 %5 %6 > c.log 2>&1
    timeout /t 60
    start powershell . \Automation.ps1 %1 %2 %3 %4 %5 %6 > d.log 2>&1
    timeout /t 60
    start powershell . \Automation.ps1 %1 %2 %3 %4 %5 %6 > e.log 2>&1
    timeout /t 60
    start powershell . \Automation.ps1 %1 %2 %3 %4 %5 %6 > f.log 2>&1
    the log files get created but are empty.  If I invoke 'call' instead of start I get the log data, but I need them to run in parallel, not sequentially.
    call powershell . \Automation.ps1 %1 %2 %3 %4 %5 %6 > a.log 2>&1
    timeout /t 60
    call powershell . \Automation.ps1 %1 %2 %3 %4 %5 %6 > b.log 2>&1
    timeout /t 60
    call powershell . \Automation.ps1 %1 %2 %3 %4 %5 %6 > c.log 2>&1
    timeout /t 60
    call powershell . \Automation.ps1 %1 %2 %3 %4 %5 %6 > d.log 2>&1
    timeout /t 60call powershell . \Automation.ps1 %1 %2 %3 %4 %5 %6 > e.log 2>&1
    Any suggestions of how to get this to work?

    Batch files are sequential by design (batch up a bunch of statements and execute them). Call doesn't run in a different process, so when you use it the batch file waits for it to exit. From CALL:
    Calls one batch program from another without stopping the parent batch program
    I was hoping for the documentation to say the batch file waits for CALL to return, but this is as close as it gets.
    Start(.exe), "Starts a separate window to run a specified program or command". The reason it runs in parallel is once it starts the target application start.exe ends and the batch file continues. It has no idea about the powershell.exe process
    that you kicked off. Because of this reason, you can't pipe the output.
    Update: I was wrong, you can totally redirect the output of what you run with start.exe.
    How about instead of running a batch file you run a PowerShell script? You can run script blocks or call individual scripts in parallel with the
    Start-Job cmdlet.
    You can monitor the jobs and when they complete, pipe them to
    Receive-Job to see their output. 
    For example:
    $sb = {
    Write-Output "Hello"
    Sleep -seconds 10
    Write-Output "Goodbye"
    Start-Job -Scriptblock $sb
    Start-Job -Scriptblock $sb
    Here's a script that runs the scriptblock $sb. The script block outputs the text "Hello", waits for 10 seconds, and then outputs the text "Goodbye"
    Then it starts two jobs (in this case I'm running the same script block)
    When you run this you receive this for output:
    PS> $sb = {
    >> Write-Output "Hello"
    >> Sleep -Seconds 10
    >> Write-Output "Goodbye"
    >> }
    >>
    PS> Start-Job -Scriptblock $sb
    Id Name State HasMoreData Location Command
    1 Job1 Running True localhost ...
    PS> Start-Job -Scriptblock $sb
    Id Name State HasMoreData Location Command
    3 Job3 Running True localhost ...
    PS>
    When you run Start-Job it will execute your script or scriptblock in a new process and continue to the next line in the script.
    You can see the jobs with
    Get-Job:
    PS> Get-Job
    Id Name State HasMoreData Location Command
    1 Job1 Running True localhost ...
    3 Job3 Running True localhost ...
    OK, that's great. But we need to know when the job's done. The Job's Status property will tell us this (we're looking for a status of "Completed"), we can build a loop and check:
    $Completed = $false
    while (!$Completed) {
    # get all the jobs that haven't yet completed
    $jobs = Get-Job | where {$_.State.ToString() -ne "Completed"} # if Get-Job doesn't return any jobs (i.e. they are all completed)
    if ($jobs -eq $null) {
    $Completed=$true
    } # otherwise update the screen
    else {
    Write-Output "Waiting for $($jobs.Count) jobs"
    sleep -s 1
    This will output something like this:
    Waiting for 2 jobs
    Waiting for 2 jobs
    Waiting for 2 jobs
    Waiting for 2 jobs
    Waiting for 2 jobs
    Waiting for 2 jobs
    Waiting for 2 jobs
    Waiting for 2 jobs
    Waiting for 2 jobs
    Waiting for 2 jobs
    When it's done, we can see the jobs have completed:
    PS> Get-Job
    Id Name State HasMoreData Location Command
    1 Job1 Completed True localhost ...
    3 Job3 Completed True localhost ...
    PS>
    Now at this point we could pipe the jobs to Receive-Job:
    PS> Get-Job | Receive-Job
    Hello
    Goodbye
    Hello
    Goodbye
    PS>
    But as you can see it's not obvious which script is which. In your real scripts you could include some identifiers to distinguish them.
    Another way would be to grab the output of each job one at a time:
    foreach ($job in $jobs) {
    $job | Receive-Job
    If you store the output in a variable or save to a log file with Out-File. The trick is matching up the jobs to the output. Something like this may work:
    $a_sb = {
    Write-Output "Hello A"
    Sleep -Seconds 10
    Write-Output "Goodbye A"
    $b_sb = {
    Write-Output "Hello B"
    Sleep -Seconds 5
    Write-Output "Goodbye B"
    $job = Start-Job -Scriptblock $a_sb
    $a_log = $job.Name
    $job = Start-Job -Scriptblock $b_sb
    $b_log = $job.Name
    $Completed = $false
    while (!$Completed) {
    $jobs = Get-Job | where {$_.State.ToString() -ne "Completed"}
    if ($jobs -eq $null) {
    $Completed=$true
    else {
    Write-Output "Waiting for $($jobs.Count) jobs"
    sleep -s 1
    Get-Job | where {$_.Name -eq $a_log} | Receive-Job | Out-File .\a.log
    Get-Job | where {$_.Name -eq $b_log} | Receive-Job | Out-File .\b.log
    If you check out the folder you'll see the log files, and they contain the script contents:
    PS> dir *.log
    Directory: C:\Users\jwarren
    Mode LastWriteTime Length Name
    -a--- 1/15/2014 7:53 PM 42 a.log
    -a--- 1/15/2014 7:53 PM 42 b.log
    PS> Get-Content .\a.log
    Hello A
    Goodbye A
    PS> Get-Content .\b.log
    Hello B
    Goodbye B
    PS>
    The trouble though is you won't get a log file until the job has completed. If you use your log files to monitor progress this may not be suitable.
    Jason Warren
    @jaspnwarren
    jasonwarren.ca
    habaneroconsulting.com/Insights

  • Source path too long :-Unable to delete mutiple number of folder and files from windows 2008 R2 file server

    Hi Team,
    we have a file server on windows server 2008 R2, I have copied some data from one server to another server using robocopy . I have checked access permission it seems okay no issues with access permission. but when i am trying to delete these folder i am
    getting below error message
    Error message:- 
    The source file name are larger than is supported by the file system.try moving to a location which has a shorter path name or try renaming to shortcut names before attempting this operations
    Regards,
    Triyambak 
    Regards, Triyambak

    I have tried everything , but nothing help , getting same error 
    could any one help me regarding this.
    Regards, Triyambak
    I have not looked at the other thread mentioned, but usually when this ends up happening, There are several ways to go about it.    One is to map a drive to the UNC path deeper into the folder structure.   
    So instead of C:\long\path\that\we\dont\want\files\in
    You map a drive.. lets say M:\   to     \\computer\c$\long\path\that\we\dont\want
    Now, when you open Explorer to M:\ you've elimintated the length of the path down to M:\files\in which is completely usable.
    The other way, is to shorten the names of everything.    For example...
    Folder structure like this:
    Root
    -----Folder1
    -----Folder2
    --------------Folder2A
    -----Folder3
    --------------Folder3A
    Rename all the folders to shorten up the path.     Rename Folder1 to '1' Rename Folder2 to '2', Rename folder3 to '3.    Then try to delete.  If it's still too long,  go one folder deeper.   Rename Folder2A to '1'  and
    Rename Folder3A to '1' and so on.     Basically keep renaming everything to a single digit character and eventually you'll shrink the path down to where you can shift-delete everything remaining.
    Hope that helps.    
    Brian / ChevyNovaLN

  • How to re-create playlists from Windows iTune library file?

    After importing my itunes library from a Windows 7 sledded HDD, I have all my music etc but no playlists.
    The kb article that explains the importing of the library files (itl and .xml) give some warnings about doing this import.
    I can see both the xml file and a number of recent itl files on the sledded drive.
    Am I going to mess anything up by importing these? It's possible that some of the songs the playlists pointed to are no longer in iTunes (I deleted some beore the import). Is this going to cause a problem.
    Will this even work?

    Assuming your relocated library is now at *Z:\iTunes Media*, for example, copy the library files that you restored onto drive C: (iTunes Library.itl, iTunes Library Extras.itdb, iTunes Library Genius.itdb, sentinel & Album Artwork folder - ignore the .xml) into the parent of this folder, i.e. Z:\, then click the icon to launch iTunes and *immediately press and hold the SHIFT key* until presented with an option to choose or create a library. Choose the library at Z:\ - all should be well. If I guessed wrong just use your actual media folder & parent of that media folder as approptiate.
    tt2

  • WINDOWS 7 .bat file to Linux share

    Hi
    We have two new windows 7 pcs which have their drives mapped at net log on.  
    Every drives maps until it reaches that drive located on a Linux server.  Which at this point the user is prompted for a password,
    when the details are entered the drive doesn't map.
    the batch file works on windows xp pc's fine the only difference appears to be windows 7

    Hi,
    You may update all the drivers and ensure all the updates have been applied.
    This can also be caused if your DHCP server is slow/congested, or if your LAN switch is having trouble putting the port in the right VLAN
    Can you run the batch in Safe Mode with networking? If it works, I suspect that the issue is caused by your security programs or firewall.
    You may try to manually use  UNC (\\server\share) and IP (\\ip.add.res.s\share) to map the drive for a test.
    Hopefully you could resolve your issue soon.
    Regards,
    Blair Deng
    Blair Deng
    TechNet Community Support

  • Making a bootable disk usable with bot camp from windows 7 .img file?

    I downloaded windows 7 and have an .img file. I want to make a bootable disk so that i can use it with bootcamp. I have tried burning the .img file to a disk but bootcamp does not recognize it. Does anyone know how I can do this? I have a 2011 macbook pro

    Hello Vetusto, welcome to Lenovo forums!
    Thanks for your instruction to install Linux from an USB stick!
    But I think it´s enough to keep one thread running on this topic. So we won´t split the discussion into different areas of this forum.
    It´s totally ok, if you point users, who are interested in this topic, from the X board to this thread, if necessary.
    Follow @LenovoForums on Twitter! Try the forum search, before first posting: Forum Search Option
    Please insert your type, model (not S/N) number and used OS in your posts.
    I´m a volunteer here using New X1 Carbon, ThinkPad Yoga, Yoga 11s, Yoga 13, T430s,T510, X220t, IdeaCentre B540.
    TIP: If your computer runs satisfactorily now, it may not be necessary to update the system.
     English Community       Deutsche Community       Comunidad en Español

Maybe you are looking for

  • Sound loss while playing movie on iTunes

    Whenever I try to play a movie like Epic or Frozen.  Sound is lost after about 20 minutes during the movie.  I tried using programs to clear things up, put it does not help.  Any advise?

  • Lightroom 4.2 catalog and importing problems

    I have imported photos into the catalog but when I go to import new photos from the same folder it does not recognize the already imported photos and lists them as new photos still.  Also, it won't import any video files of any extension even though

  • Noise on wake up, Hel...

    A couple of days ago I noticed the right speaker on my Macbook started to make a "swoosh" sound (even with the volume turned completely down). This happens after I have waked up the Macbook from sleep and entered by login password... the "swoosh" noi

  • Planning a production system for SAP portal

    Hello Experts- Can any one of you point me to some document or blogs on best practises on designing production portal. I am not looking for best practics implementing portal, but just production system. Thanks, John.

  • Controlling the sender/recipient name that appears on iCloud Mail messages.

    My husband and I both use our one alias iCloud mail accounts. Both the alias and the main account were created in my name (not his) and yet his name appears as the sender and recipient on messages sent and received through the alias. I've rechecked s