How to execute sql statement under bat file?

I want to execute following statement
C:\>sqlplus /nolog
SQL> conn scott/tiger
SQL> select * from tab;
I know I can realize it as following test.bat and testdb.sql file
test.bat is follows:
sqlplus /nolog @testdb.sql
testdb.sql is follows:
conn scott/tiger
select * from tab;
Now I don't want to use sql file,I only want to use bat file,like follows:
test.bat is follows:
sqlplus /nolog
conn scott/tiger
select * from tab;
when I run test.bat,I find only sqlplus /nolog statement execute,the other statements don't execute.
1)I want to know whether there is a method to execute sql statement only by bat file without a sql file? How to realize it?
2)If I call sql file,how to hide passord of user? Because I don't want to other persons know scott password,if I use conn scott/tiger in testdb.sql,other person can see testdb.sql and know the password. Is there a good method to avoid?
Thanks!

I'm running *NIX, but works the same on Windows
bcm@bcm-laptop:~$ cat here.sh
sqlplus dbadmin/admindb << EOF
select count(*) from user_objects;
exit
EOF
bcm@bcm-laptop:~$ sh here.sh
SQL*Plus: Release 11.2.0.1.0 Production on Mon May 17 18:14:09 2010
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>
  COUNT(*)
      9
SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
bcm@bcm-laptop:~$ Edited by: sb92075 on May 17, 2010 6:15 PM

Similar Messages

  • How to export the result from executing sql statement to excel file ?

    HI all,
    Great with Oracle SQL Developer, but I have have a trouble as follwing :
    I want to export the result from executing sql statement to excel file . I do easily like that in TOAD ,
    anyone can help me to do that ? Thanks so much
    Sigmasvn

    Hello Sue,
    I just tried to export to excel with the esdev extension and got java.lang.NumberFormatException. I found the workaround at Re: Windows Multi-language env, - how do I set English for application lang?
    open the file sqldeveloper\jdev\bin\sqldeveloper.conf and add the following two lines:
    AddVMOption -Duser.language=en
    AddVMOption -Duser.country=USyet now my date formats in excel are 'american-style' instead of german. For example 01-DEC-01 so excel does not recognize it as date and therefore I can not simply change the format.
    When export to excel will be native to 1.1 perhaps someone can have a look at this 'feature'
    Regards
    Marcus

  • How to run sql query in bat file in task schedular at every 10 seconds

    This is my sql script :
    DECLARE @countRows INT,
    @currDate DATE,
    @checkForTasks INT,
    @created_by_id INT,
    @gst_ID int;
    SET @currDate = Getdate()
    SET @countRows = (SELECT Count(*)
    FROM [dbo].[sd_gst_effective_table]
    WHERE isapplied = 0)
    IF @countRows > 0
    -- Check for those GST''s who are not applied yet : if they are greater than 0 then perform next task
    BEGIN
    SET @checkForTasks = (SELECT Count(*)
    -- Check is current date equals to task date or not
    FROM [dbo].[sd_gst_effective_table]
    WHERE effect_date = @currDate AND isapplied = 0)
    IF @checkForTasks > 0
    -- If current date = task date then perform this task
    BEGIN
    SET @created_by_id = (SELECT TOP 1 createdby FROM [dbo].[sd_gst_effective_table] WHERE effect_date = @currDate AND isapplied = 0)
    SET @gst_ID = (SELECT gst_id FROM [dbo].[sd_gst_effective_table] WHERE effect_date = @currDate AND isapplied = 0)
    -- STEP 1 :: InActivate the existing GST according to createdbyID
    UPDATE sd_gst_rate
    SET isactive = 0,
    inactivedate = Getdate()
    WHERE isactive = 1
    AND createdby = @created_by_id
    -- STEP 2 :: Activate the New GST according to implementation date and gstID
    UPDATE sd_gst_rate
    SET isactive = 1,
    activedate = Getdate()
    WHERE id = @gst_ID
    -- STEP 3 :: Inactivate the applied GST from sd_gst_effective_table
    UPDATE [dbo].[sd_gst_effective_table] SET isApplied = 1 WHERE gst_id = @gst_ID
    END
    END
    DECLARE @Text AS VARCHAR(100)
    DECLARE @Cmd AS VARCHAR(100)
    DECLARE @value nvarchar(1000);
    SET @value = (SELECT CONVERT(TIME,GETDATE()) AS HourMinuteSeconds);
    SET @Text = 'File Writed ' + @value
    SET @Cmd ='echo ' + @Text + ' > E:\AppTextFile.txt'
    EXECUTE Master.dbo.xp_CmdShell @Cmd
    This is resided in videos folder of windows , i have created a task schedular in windows 8.1 to run daily at every 10 seconds , but it is not working ... Please tell me how to deal with it.
    Please note : This sql query is running perfectly in sql server. Query have no errors. Please check whats wrong with my time schedular. I just want my schedular to run every 10 seconds regardless of date.

    Hi Emad,
    Is your script in a ".sql" file? May I know how you configure the schedule task action?
    Since you didn't mention how you configure the schedule task, can you confirm you have followed the below step correctly?
    Save your script in a ".sql" file.
    Create a ".bat" file and call the sql file above inside with
    sqlcmd.exe, you can reference
    here.
    Configure a schedule task to run the ".bat" file in a certain interval.
    Have you tried to run the script in you bat file in a standalone commandline window? Please post the script in your bat file, It can help to diagnose the issue.
    If you have any question, feel free to let me know.
    Eric Zhang
    TechNet Community Support

  • Load sql statement in .bat file

    Hi
    I need to execute a simple sql command eg: +"truncate table tab1"+ from a DOS batch file...
    my bat file contains following statement
    sqlplus dilanjan/dilanjan@XE @trun.sql
    my trun.sql file contains following statement
    truncate tabe base
    once I save the .bat file and double click it. It connects to database but the table is not getting truncated...
    Some one please help me with this!

    What does your screen output show you.
    Did you try to execute the statement in the batch file manually?
    Are the files in the same directory?
    Please post some screen output
    Thanks
    FJFranken

  • How to execute SQL statement with oracle jdev

    Please I'm a beginner in oracle jdeveloper. I want to know how to use and execute sql statememt within oracle Jdeveloper 10 g release 3 to manipulate objects in oracle database. I want for e.g. to Enable/disable trigger using sql statement "ALTER TRIGGER trigername DISABLE" explicitly. Please tell me how to proceed.
    i am sure you can help me
    Sincerly yours.

    Hi,
    Using following tutorial http://www.oracle.com/technology/obe/ADF_tutorial_1013/10131/index.htm
    you will found how to connect from Jdev to a database (chapter 1 or 2 ?). Then you just have to go under Tool>SQL*Plus or Tools>SQL Worksheet depending on what you need.
    Luck,
    Tif

  • 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 Execute SQL Statements From Shell Scripts?

    I need to extecute some SELECT statements from a shell scripts. Could anybody kindly tell me how to do that, or which document i should refer to ? Thank you very much!

    You can execute SQLPlus with the SQL in a file (sqlplus -s @<sql-script>).

  • Batch executing SQL Statements stored in a file in SAP DB

    hi,
    I am using SAP DB as database in my j2ee application. As a part of the application purpose, i need to insert a large no. of records in to the database directly. I have created the SQL file which contains the insert statements for the records
    Now i need to execute this file sothat the insert statement which are inside the file get executed. I am using SQL Studio to access to the Database.
    I would like to know whether any options are available in SQL Studio to for executing a SQL File.
    Kindly help
    Best regards,
    Sudheesh...

    Hi,
    I believe that the solution to your problem lies in creating sql studio objects.Please refer to the link below.Select the link "sql dialog" on the page.
    The following options are available for sql dialog.
    The following options are available in the SQL dialog:
    ·        Creating and executing SQL statements
    ·        Setting parameters for SQL statements
    ·        Importing and exporting SQL statements
    Select the "Importing and exporting sql statements" link on this page to know more about it.This will tell you how to import sql statements from ascii files.
    Basically,what you need to do is From the context menu for the SQL dialog, choose Import File or Export File.
    The link I have provided,gives a lot of other information as well.
    http://help.sap.com/saphelp_nw04s/helpdata/en/ee/1c5bdfeba711d4aa2800a0c9430730/frameset.htm
    Hope this helps.
    Regards,
    Harish
    (Please award points for helpful answers)
    Message was edited by: HARISH SUBRAMANIAN

  • Run sql statement from batch file

    How can we execute SQL Statement using Batch file???
    I did a test.
    create batch file test.bat
    sqlplus "username@db /pass" @\script.sql
    script.sql file has following statement
    select sysdate from dual;
    exit
    it is working but I want to call sql statement in the same batch file instead of calling .sql script file. how can I do that any idea..

    This is very easy in unix shell scripting, but AFAIK, not available with Windows. It's a function of how the shell/command processor handles input redirection.

  • How could I extract past executed SQL statement from dictionary ?

    We use oracle11gR2 on win2008R2.
    How could I extract the past executed SQL statement from dictionary ? (Is it possible from V$SQLTEXT or other dictionary table ?)

    IvicaArsov wrote:
    Hi,
    You can find executed SQL in V$SQLAREA view (if it's still in memory). If it does'n't exist and you have AWR enabled you can query DBA_HIST_SQLTEXT table, but remember that the statistic information in AWR tables is filtered (1 out of 10).
    I.Arsov
    As you know when taking snapshot oracle will capture only top sql statements and stored in AWR.
    But can you please link(source) dba_hist_sqltext contain only 1 out of 10 filtered data?. In dba_hist_active_sess_history yes it contain 1 out of 10 sampled data.

  • Error executing SQL statement

    Hi,
    Can anyone see why I am getting this error message for my SQL query?
    WITH SKU_DATA AS (
    SELECT /*+ MATERIALIZE */ DISTINCT FROM_LOC_ID,
               SKU_ID,
               DESCRIPTION,
               UPDATE_QTY,
            ORDER_ID,
            CONSIGNMENT,
               WEIGHT,
            PALLET_ID,
            CASE 
        WHEN Upd_Qty_Ratio < 1
        THEN TO_CHAR(UPDATE_QTY) || 'U'
        WHEN TRUNC(Upd_Qty_Ratio) = Upd_Qty_Ratio
        THEN TO_CHAR(Upd_Qty_Ratio) || 'C'
        ELSE TO_CHAR(TRUNC(UPDATE_QTY)) || 'C' || ' ' || TO_CHAR(ROUND(MOD(Upd_Qty_Ratio, 1) *  USER_DEF_NUM_3, 6)) || 'U'
        END CU_Sum
        FROM (
      SELECT DISTINCT
             FROM_LOC_ID,
          S.SKU_ID,
             S.DESCRIPTION,
             ITL.UPDATE_QTY,
             S.USER_DEF_NUM_3,
          OH.ORDER_ID,
          ITL.CONSIGNMENT,
          ITL.PALLET_ID,
             NVL(ITL.UPDATE_QTY,0)*NVL(S.EACH_WEIGHT,0) Weight,
             ITL.UPDATE_QTY/(CASE S.USER_DEF_NUM_3 WHEN 0 THEN 1 ELSE S.USER_DEF_NUM_3 END) Upd_Qty_Ratio
        FROM INVENTORY_TRANSACTION ITL, SKU S, LOCATION L, ORDER_HEADER OH
        WHERE ITL.SKU_ID = S.SKU_ID
        AND ITL.CODE = 'Pick'
        AND ITL.CONSIGNMENT = $P{Consignment}
        AND OH.ORDER_DATE = TO_CHAR($P{Date}, 'DD-Mon-YYYY')
        AND OH.ORDER_ID = ITL.REFERENCE_ID
        AND ITL.TO_LOC_ID = 'CONTAINER'))
    SELECT DISTINCT ORDER_ID, CONSIGNMENT, WEIGHT, PALLET_ID, CU_Sum,
    (SELECT NVL(TO_CHAR(SUM(CASE WHEN NULLIF(SUBSTR(Cu_Sum, -1), 'U') IS NULL THEN NULL ELSE REPLACE(Cu_Sum,'C',NULL) END)),'0') ||'C' || ' ' || NVL(TO_CHAR(SUM(CASE WHEN NULLIF(SUBSTR(Cu_Sum, -1), 'C') IS NULL THEN NULL ELSE REPLACE(Cu_Sum,'U',NULL) END)),'0') ||'U' FROM SKU_DATA) AS Total_Cu_Sum
    FROM SKU_DATAThanks in advance.
    SM.

    Hi Sean,
    It is saying error executing SQL statement, but with no "ORA error" so maybe its a Jasper Reports error i'm not too sure.
    And this is a different version of the one we done together, that one is running fine just having problems putting the jasper file on to the server. I'm just using the main bits from the original SQL.
    SM

  • How to execute sql from table

    For a migration I have created a sql script that puts the full statement to be executed in a specific table column
    I'm now looking for a way how to execute those statements.
    Table structure like: oldName, newName, sqlStatement, id, otherField, otherField2
    Instead of the full statement(sqlStatement) it would also be possible to use the oldName, newName and id field if that simplifies the problem.
    The reason for building the statement and running that one is a) to validate upfront b) a self join is applied to the query result table to prevent some items for update.
    The initial idea was to take the sql statements and execute them as a sql script but that process is pretty slow.

    user2833655 wrote:
    For a migration I have created a sql script that puts the full statement to be executed in a specific table column
    I'm now looking for a way how to execute those statements.That is wrong, tables are for data not executable code
    Re: ref cursor - result set not known
    http://en.wikipedia.org/wiki/Data_%28computing%29
    >
    Data is often distinguished from programs. A program is a sequence of instructions that detail a task for the computer to perform. In this sense, data is thus everything that is not program code.
    >
    user2833655 wrote:
    The initial idea was to take the sql statements and execute them as a sql script but that process is pretty slow.This alternative will just make it difficult, complicated and unreliable as well.

  • SQL statements in XML File

    Folks
    I need to separate SQL statements from Java Code, How do i put these SQL Statements in an XML file and how to access these SQL statements from a Java code,
    Any help with sample code is greatful,

    The use of entities as kstc_jyu may help. It really depends on how you design the XML vocabulary based on the expected usage (e.g., if the SQL statements change very often).
    Back to the original question, I am right to interpret "how to use SQL statements in XML ?" as how to design an XML vocabulary to store SQL statements?
    If not, you can simply use the scheme proposed by DrClap. Reading and extracting the SQL statement would be just as you would with any other XML document. Google for a Java XML tutorial.

  • How to retrieve SQL statement in the CR 2008

    I'm using Crystal Reports 2008 in MS Visual Studio 2008, how can i retrieve SQL statement from *.rpt file, i have tried this code, but it doesn't work:
    ReportDocument rdReport = new ReportDocument();
    rdReport.Load("Reports/EmployeeTest.rpt", OpenReportMethod.OpenReportByTempCopy);
    CrystalDecisions.ReportAppServer.Controllers.RowsetController rsController;
    CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument rdClient = rdReport.ReportClientDocument; // on this line it throws an exception "The ReportClientDocument property can only be accessed when the report is opened using a Report Application Server."
    CrystalDecisions.ReportAppServer.DataDefModel.ISCRGroupPath rdGroupPath = new CrystalDecisions.ReportAppServer.DataDefModel.GroupPath();
    string temp;
    string sql;
    rsController = rdClient.RowsetController;
    sql = rsController.GetSQLStatement(rdGroupPath, out temp);
    maybe i'm doing something wrong ?
    thanks

    Hello Ludek,
    when I try to get the report from the session I got an error like this (I am using State Server Session mode i.e out proc in my application)
    ReportClientDocument     'reportDocument.ReportClientDocument' threw an exception of type 'System.InvalidOperationException'     CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument {System.InvalidOperationException}
    +base     {"The ReportClientDocument property can only be accessed when the report is opened using a Report Application Server."}     System.SystemException {System.InvalidOperationException}
    StackTrace     "   at CrystalDecisions.CrystalReports.Engine.ReportDocument.get_ReportClientDocument()"     string
    so is it the problem of not opened with RAS. Does installation of RAS solves the problem, If so Is it a free-ware or needs to be purchased.
    Ashok

  • How to execute sql qurery in st05

    how to execute sql qurery in st05
    thanks in advanced.

    Hi,
    do this....
    1.create a small ABAP/4 program that contains only the select statement. Before proceeding, test it to ensure that it works.
    2.Open that program in the editor so that it is ready and waiting to execute.
    3.Open a new session using the menu path System->Create session.
    4.Run transaction ST05 (enter /nst05-zero-five, not oh-five-in the Command field, or choose the menu path System->Utilities->SQL Trace). The Trace SQL Database Requests screen is displayed.
    5.If the Trace SQL Status Information box reads Trace SQL is switched off, go to step 7.
    6.At this point, the Trace SQL Status Information box contains Trace SQL switched on by, followed by the user id who turned on the trace and the date and time it was started. You must switch it off before you can proceed. If the trace was started within the past hour, it is possible that it is still being used. Contact the indicated user or try again later. If the trace was started hours or days ago, the user probably left it on by mistake and it can be safely turned off. To turn off the trace, press the Trace Off pushbutton. The message in the Trace SQL Status Information box should now read Trace SQL is switched off.
    7.Press the Trace On pushbutton. The Trace SQL Database Requests dialog box is displayed. The DB-Trace for User field should contain your user ID. If your user ID is not in this field, enter it now.
    8.Press the OK button. You are returned to the Trace SQL Database Requests screen and the status information reads Trace SQL switched on by, indicating that you turned on the trace.
    9.Switch back to the window containing your editor session (the one with your program waiting to execute).
    10.Press F8 to run your program. (Only press F8, do not do anything else, do not even press the Back button.)
    11.When your program has run and the hourglass is no longer displayed, switch back to the trace window.
    12.Press the Trace Off pushbutton. The status information reads Trace SQL is switched off.
    13.Press the List Trace pushbutton. The Trace SQL Database Requests dialog box is displayed. The fields on this screen will already contain values.
    14.Press the OK button. You might need to wait a little while, at most a couple of minutes. The Trace SQL: List Database Requests screen is displayed.
    15.Type %sc in the Command field and press the Enter key. The Find dialog box is displayed.
    16.Type the name of the table you are tracing in the Search For field. (This is the table named in the select statement in your ABAP/4 program.)
    17.Press the Find button. A search results list should be displayed with your table name highlighted.
    18.Click on the first highlighted table name. You are returned to the Trace SQL: List Database Requests screen. Your cursor is positioned on the first line containing your table name. To the right of it, in the Operation column, should be the word PREPARE, OPEN, or REOPEN.
    19.Press the Explain SQL button on the Application toolbar. The Show Execution Plan for SQL Statement screen is displayed.
    20.Scroll down to the execution plan. The index used will be displayed in blue.

Maybe you are looking for

  • I can't open my bookmarks

    When I was downloading Firefox I was not asked if I wanted to import my bookmarks from IE, but after the download was finished most of the bookmarks were there in the toolbar. The problem is, none of them will open for me.

  • I can't find the bar that lets you do things in photoshop

    my version of photoshop cs6 seems to be missing the entire bar that allows you to work? the one with the open, window, file and edit buttons. I use a 13 inch macbook pro, is it something to do with my screen size or my copy of photoshop?

  • Inssue regrading business place .

    Dear All, There is a problem when we are trying to post the goods issue. System is showing a message saying that the business place is not found for plant . Please provide the solution for the same. Regards, Gautam.

  • Install oracle9iR2 in redhat

    i want to install oracle9i R2 in linux redhat but im having same problem if any one can help me, what i did :\ *i create oracle user *i add the user to  oinstall group *su - oracle * edit /.bash_profile *after that i loade the prodect in home dirctor

  • Ripping music tracks from CDs

    What file type, bit rate, etc. should I use when ripping CDs to a hard drive?  I am planning eventually to serve the songs files for listening via a Sonos device and hope to preserve the best possible sound quality.  Thanks!