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

Similar Messages

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

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

  • 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

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

  • Tooooooooo slow connect by sqlplus from windows 2008 to windows 2003

    hello i'm mr.kang from korea
    i wana quick connect by sqlplus below envirunment
    plzzzzzzz help me!!!!!
    have a nice day~:)
    from :
    OS : Windows 2008
    Client : Oracle Database 10g Client Release 2 (10.2.0.3)
    to :
    OS : Windows 2003
    DB : Oracle Database 10g Release 2 (10.2.0.1.0) for Microsoft Windows
    Edited by: user581964 on Oct 31, 2009 8:42 AM

    Fahd Mirza wrote:
    Would you please shed more light on masking the higher order of IP address?
    regardsJust to confirm what Niall said, I just meant to obscure it from public viewing when posting back to here. The 'high-order' end would be the left most octet .. Say your IP address is 111.222.333.444, when posting to a public forum such as this you'd show it as ***.222.333.444 or xxx.222.333.444. This is a security issue, so you don't expose your network to the world. It is best to just obscure the high-order part, because the OP's problem could be due to mis-matched IP addresses, and we'd miss spotting that if the entire address were masked and it is usuallly the low-order end where the discrepancies come.
    and if you think this is being overly cautious .... there was a thread on c.d.o.s a few years back where a careless person posted a question and revealed his entire server/domain name, and it was a U.S. military domain. I called him out on it. He replied that it didn't matter because it couldn't be reached from the outside. Another participant promptly posted back the proof that it was accessible ...

  • 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

  • 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

  • Problem connecting DataBase Link from windows oracle to oracle on Linux

    I'm facing a problem with database links from windows oracle to Oracle hosted on Linux server.
    I'm able to successfully create the Database Link using the following query on oracle database hosted on a windows server
    CREATE DATABASE LINK SampleDB
    CONNECT TO myuser IDENTIFIED BY password
    USING 'sample';
    The tns names entry on windows for database in Linux server is as follows
    DSOFT =
    (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.100)(PORT = 1521))
    (CONNECT_DATA =
    (SERVICE_NAME = sample)
    But while executing the query "select count(*) from doctor@SampleDB;" in sql developer on windows, I'm getting the following error
    SQL Error: ORA-12154: TNS:could not resolve the connect identifier specified
    12154. 00000 - "TNS:could not resolve the connect identifier specified"
    *Cause:    A connection to a database or other service was requested using
    a connect identifier, and the connect identifier specified could not
    be resolved into a connect descriptor using one of the naming methods
    configured. For example, if the type of connect identifier used was a
    net service name then the net service name could not be found in a
    naming method repository, or the repository could not be
    located or reached.
    Using the above tns entries, i'm successfully able to connect to the database in Linux server through sql developer installed on the windows machine. Then why i'm getting this error while executing the query on Database Link?. Can any one help me?

    1005745 wrote:
    I'm facing a problem with database links from windows oracle to Oracle hosted on Linux server.
    I'm able to successfully create the Database Link using the following query on oracle database hosted on a windows server
    CREATE DATABASE LINK SampleDB
    CONNECT TO myuser IDENTIFIED BY password
    USING 'sample';
    The tns names entry on windows for database in Linux server is as follows
    DSOFT =
    (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.100)(PORT = 1521))
    (CONNECT_DATA =
    (SERVICE_NAME = sample)
    But while executing the query "select count(*) from doctor@SampleDB;" in sql developer on windows, I'm getting the following error
    SQL Error: ORA-12154: TNS:could not resolve the connect identifier specified
    12154. 00000 - "TNS:could not resolve the connect identifier specified"
    *Cause:    A connection to a database or other service was requested using
    a connect identifier, and the connect identifier specified could not
    be resolved into a connect descriptor using one of the naming methods
    configured. For example, if the type of connect identifier used was a
    net service name then the net service name could not be found in a
    naming method repository, or the repository could not be
    located or reached.
    Using the above tns entries, i'm successfully able to connect to the database in Linux server through sql developer installed on the windows machine. Then why i'm getting this error while executing the query on Database Link?. Can any one help me?A database link is acting as a client to the target, remote database in exactly the same fashion and using exactly the same tns infrastructure as any other client trying to connect to that remote database. your ORA-12154 when querying a db link means exactly the same as if you had gotten it trying to connect with sqlplus, from the same server. Check the link SB provided. Keep in mind that the tnsnames file of concern is the one on the source database server.

  • Connect to Mac from Windows

    I have three Windows systems and one Mac.
    Currently, to connect to my Mac (OSX Tiger) from Windows I have to be logged into the Mac as that user on the Windows machine.
    I have three users that access the Mac. All are setup on the Mac as users. All are setup on the Windows systems as users.
    But if John logs into the Mac and Betty tries to access the Mac from her computer she cannot. If John tries to access the Mac from his Windows system he can.
    Does anyone know how to setup the Mac so that any of the three users can connect to it from Windows regardless of who is logged in?
    I tried to set the group to staff for all the users public folders but that did not help.

    The user names and passwords are the same on both systems. That is not the issue.
    The issue is that each user can only connect to the mac from their windows system when they physically log on as user at the mac.
    Otherwise it will not even show up in their network neighborhood.
    If I boot up the mac and log in as the user, I can connect to the mac from my windows system but the other two users can't.
    Likewise if one of them logs in as the user on the mac, I cannot connect to it from my windows system.

  • Problem in connecting to database from webdynpro for java

    Hi
    I have a problem in connecting to database from webdynpro application
    I am using oracle 10 express edition as database and was able to connect to database from a java application.But  was unable to connect from a webdynpro for java.
    <b>I guess webdynpro for java uses open sql instead of vendor sql(I looked in the visual admin ,DB is using open sql) so unable to connect to database.Am i right.?</b>
    Do i need to make any settings in the visual admin to make it work?
    How to solve this problem.Please give me pointers
    Thanks
    Bala

    Hi,
    For connecting to Oracle, either you can use the normal JDBC connectivty code directly which is given below :
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@Oracle_server_ip:Oracle port:SID of the Database","user_name","password");
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("your query");
    In case you want to fetch data through ejbs, these are the steps to be followed :
    1) Open the J2EE perspective
    2) Create an EJB Module project
    3) Right click on ejbModule, create a new EJB (select your EJB type)
    4) While creating the ejb itself, you can add business methods by clicking ‘Next’ in the UI. Another option is after creating the ejb, write the method in the bean, then select the method from ejb-jar.xml -> <bean name> ->method. Right click and select ‘propogate to local & remote’.
    5) Double click on ejb-j2ee-engine.xml. select your bean and specify a Jndi name for eg: “MyJndi”.
    6) Right click on the EJB project and add ‘classes12.zip’ file (provided by Oracle) to it’s build path. (under libraries tab). Also check the same file under ‘Order & Export’.
    7) Create an Enterprise Application project.
    8) Right click on the EJB module project and select add to EAR project, then select the created EAR project.
    9) Right click on the EJB project, select ‘Build EJB Archive’
    10) Right click on the EAR project, select ‘Build Application Archive’
    11) Open the WebDynpro perspective, open a new project, right click on the project ->properties. Do the following configurations :-
    • Java Build path - select the EJB project from ‘projects’ , check the selected project under ‘Order & Export’
    • Project references – select the EAR project
    • WebDynpro references – select ‘sharing references’ tab, click add & make an entry as : <vendor>/<EAR project name without .ear extension>
    You can find the vendor name under ‘application-j2ee-engine.xml’ file of the EAR project. By default it is ‘sap.com’. So if my EAR project’s name is ABC, my entry would look like ‘sap.com/ABC’
    12) Now the configurations are over and the EJB can be invoked by writing the client code inside the webdynpro component. Like:
    InitialContext context = new InitialContext();
    Object obj = context.lookup("MyJndi");
    MyEJBHome home = MyEJBHome)PortableRemoteObject.narrow(obj,MyEJBHome.class);
    MyEJB mybean = home.create();
    int a = 0;
    a= mybean.add(10,15);
    wdContext.currentContextElement().setSum(a);
    where ‘MyEJB’ is my EJB name and ‘MyJndi’ is my JNDI name
    To connect to Oracle , you can write the usual Java code (given below) as a business methos of the ejb (similar to add() method in the example). And access it like mybean.<businessMethodName>().
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@Oracle_server_ip:Oracle port:SID of the Database","user_name","password");
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("your query");
    Extracted from Re: Webdynpro and Oracle
    http://help.sap.com/saphelp_webas630/helpdata/en/b0/6e62f30cbe9e44977c78dbdc7a6b27/frameset.htm
    May be of use to understand the VA Conf /people/varadharajan.krishnasamy/blog/2007/02/27/configuring-jdbc-connector-service-to-perform-database-lookups
    Regards
    Ayyapparaj

  • 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

  • CONNECT UNIX MACHINE FROM WINDOWS USING C#

    Hi all i have a requirement to connect unix machine from windows using c# code . I have the IP Address of the unix machine and the path too.I have to make a FTP using the c# code from unix to windows and vice versa . Can anybody help me out on this . It
    would be great if have a solution for this .

    Hi
    Balamurali_Mohan,
    Please refer to the similar thread
    How to connect to unix server using c#
    The marked answer said: Use a SSH (secure shell) client wrapper for .NET to connect to the remote UNIX machine and execute commands to run your script.
    Have a look at:
    http://www.codeproject.com/KB/IP/sharpssh.aspx
    Best regards,
    Kristin
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

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

Maybe you are looking for

  • How Can I Test The Health of my Mac?

    Hello, I have a Mid-2012 13 inch MacBook Pro with 2.5 GHz, and an Intel Core i5 processor. I got this Mac about 14 months ago for Grade 8 high school work purposes (I'm in a special Digital Immersion program where all work is done on Macs). My Mac's

  • IMovie and iDVD, Stupid Upgrade Questions, Sorry Must Ask

    Okay, the deal is I have a PowerMac G4 Version 2.1 with a Combo Drive. I am upgrading to Mac OSX 3.0 so I can do certain things in iMovie and acquire a better browser. (My constraints on the iMovie project about which I've been inquiring are that at

  • My iPad2 does not appear in Network MIDI set up .... HELP!!

    I have bought an ipad 2 to control Logic Pro with AC-7 core but I cannot get Network MIDI Setup to recognise my iPad 2. I tried downloading rtp MIDI and trying to get Windows 7 to recognise my iPad 2 but still no luck. I have tried creating an Adhoc

  • Cisco ISE 1.1 patch 3

    I am installing patch 3 on version 1.1. and just noticed that the admin password had reverted back to the prevoius version. In case any one has any issues logging in try that. I am going to open a TAC case once the patch finishes installing on the ot

  • Skype icon does not appear

    I installed skype but the icon does not show up. OS is actually 4.3.3. It says it is installed and I can find it under settings, but without the icon I cannot fire it up. I'm quite new to the phone so I assume it's me, but I have had not trouble with