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

Similar Messages

  • How to execute sql-queries through shell scripting in linux?

    How to execute sql-queries through shell scripting in linux?

    http://www.oracle.com/technology/pub/articles/saternos_scripting.html
    Two simple examples:
    #!/usr/bin/env bash
    set_orafra () {
       orafra=`echo 'set heading off
       select name from v$recovery_file_dest;
       exit' | sqlplus -s / as sysdba`
    set_orafra
    echo $orafra
    #!/usr/bin/env bash
    export ORACLE_SID=instance_name
    export ORACLE_HOME=/path_to_oracle_home_directory
    export LD_LIBRARY_PATH=$ORACLE_HOME/lib
    export PATH=/$ORACLE_HOME/bin/$PATH
    $ORACLE_HOME/bin/sqlplus -s <<EOF
    connect scott/tiger@my_instance_name
    INSERT INTO table VALUES (sysdate);
    exit
    EOFEdited by: Markus Waldorf on Sep 17, 2010 12:19 AM

  • Calling SQL statements from Shell scripts

    Hi,
    I want to call external package procedures, declare some variables & do some oracle validations in the shell script.
    How SQL environment is set in shell script & is this one time process or I have to write few statements before every SQL statement.
    Please explain with an example.
    Thanks..

    is this one time process Yes. Example :
    $ cat script.sh
    export ORACLE_HOME=/home/oracle/base/OraHome10
    export ORACLE_SID=db102
    export PATH=$ORACLE_HOME/bin:$PATH
    sqlplus -s / as sysdba << EOF
    select to_char(sysdate,'dd/mm/yyyy hh24:mi:ss') date_time
    from dual;
    exit
    EOF
    sqlplus -s / as sysdba << EOF
    col global_name for a60
    select * from global_name;
    exit
    EOF
    $ ./script.sh
    DATE_TIME
    27/02/2008 11:11:27
    GLOBAL_NAME
    DB102
    $

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

  • 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

  • Sample code of how to execute sql loader from visual basic

    Hi,
    Can anyone please provide me with sample code of how to
    run sql loader from inside a visual basic 6.0 application with Oracle 8.1.7.3 database or please point me to documentation/tech books containing such examples?
    Thanks very much
    John

    You have to use the command shell to activate a file.bat. The Shell command has the following parameters :
    Shell(Pathname, Windows Style )
    [email protected]
    Joel P�rez

  • How to execute sql file from servlet

    Hi,
    I am using JSP, Servlets and Oracle 8i in my application. I want to execute .sql file from java code. Is it possible to do that,
    as we execute .sql file from sql plus prompt.
    Suppose I have abc.sql file and I want to execute it from java code.
    If any body have the solution then pl. reply with sample code.
    Thanks,
    Rajesh

    If any body have the solution then pl. reply with
    sample code.No, no, dec - s/he doesn't want the actual solution, but the full code!
    /k1

  • How to get SQL statement from (Collection) query.execute();

    We have a JDO Persistence class ClassName that execute query using following code. After this statement get executed, record does not get updated in the DB. Is there a way to check what SQL statement got submitted in the (Collection) query.execute(); ??? <br><br>
    Extent extent = pm.getExtent(ClassName.class, false); <br>
    Query query = null; <br>
    try { <br>
    query = pm.newQuery(extent, filter); <br>
    Collection results = (Collection) query.execute();<br>
    Iterator i = results.iterator();<br>
    if (i.hasNext()) {<br>
    ...<br>
    }<br>

    You can always find out the names of tables that are views, using java.sql.DatabaseMetaData and its getTables() method.
    This tends to be a nice source of examples:
    javaalmanac.com
    However, if you're asking for the underlying SQL used to CREATE VIEW, I don't see anything in the API that will give you that. After all, JDBC shouldn't have to know if it's dealing with an ordinary table or a view. I think you'd have to ask your DBA for the underlying SQL.
    Once you have it, what do you plan to do with it?
    %

  • Looping through SQL statements in shell script

    Hello members,
    I'm working on the Solaris environment and the DB i'm using is Oracle 10g. Skeleton of what I'm attempting;
    Write a ksh script to perform the following. I have no idea how to include my sql query within a shell script and loop through the statements. Have therefore given a jist of what I'm attempting, below.
    1. Copy file to be processed (one file at a time, from a list of 10 files in the folder ).
    for i in *
               do
               cp $i /home/temp[/CODE]2 . Create a snapshot(n) table : Initialize n = 1 -- -- To create my snapshot table and inserts records in SQL
    create table test insert account_no, balance from records_all;3. Checking if the table has been created successfully:
    select count(*) from snapshot1 -- query out the number of records in the table -- always fixed, say at 400000
    if( select count(*) from snapshot(n) = 400000 )
    echo " table creation successful.. proceed to the next step "
    else
    echo " problem creating table, exiting the script .. "  4. If table creation is successful,
    echo " select max(value) from results_all " -- printing the max value to console
    5. Process my files using the following jobs:
    ./runscript.ksh - READ -i $m ( m - initial value 001 )
    ./runscript.ksh - WRITE -i $m ( m - initial value 001 -- same as READ process_id )
    -- increment m by 1
    6. Wait for success log
    tail -f log($m)* | -egrep "^SUCCESS"7. looping to step1 to :
    Copy file 2 to temp folder;
    create snapshot(n+1) table
    Exit when all the files have been copied for processing.
    done -- End of Step 1
    Pointers on getting me moving will be very valuable.
    thanks,
    Kris

    Hi,
    Are you inserting the data from file or from some table.
    If it is from file, I suggest sql loader would be better, I suppose.
    If it is from table, then something like this
    for i in *
               do
    sqlplus username/password@db_name<<EOF
                create table test select * account_no, balance from records_all;
    EOF
    exit
    doneAnurag

  • Calling SQL statement from a script problem

    Hello,
    I have a script e.g query.sh:
    #!/bin/sh
    sqlplus -s ${ORACLE_USER} << HIC
    set heading off
    set newpage none
    SELECT 'ALTER TABLE '||'TEST_TABLE'||' ADD PARTITION '||' P'|| TO_CHAR(TRUNC(sysdate+7), 'IYYY')||'W'|| TO_CHAR(TRUNC(sysdate+7), 'IW')||' VALUES LESS THAN(TO_DATE('''|| TO_CHAR(sysdate + 14, 'YYYYMMDD')||''',''YYYYMMDD''));' FROM DUAL;
    exit
    HIC
    This will actually give me: ALTER TABLE TEST_TABLE ADD PARTITION P2010W46 VALUES LESS THAN(TO_DATE('20101122','yyyymmdd'));
    I am executing this output from the second script. e.g create_part.sh
    #!/bin/sh
    SQL=`/home/bill/scripts/query.sh`
    sqlplus ${ORACLE_USER} << EOF
    set serveroutput on size 1000000
    set heading off
    $SQL
    exit
    EOF
    When I am running the 2nd script I am getting:
    SQL> SQL> SQL> SQL> 2 ALTER TABLE test_table ADD PARTITION P2010W46 VALUES LESS THAN(TO_DATE('20101122','yyy
    ERROR at line 1:
    ORA-01861: literal does not match format string
    I suspect that the output from the 1st script wraps to a second line, and it failes to execute properly.
    Oracle is 9i
    Please suggest a way to overcome this problem.
    Thank you in advance.

    If you are not passing in any variable values that you need the shell to substitute intot he source then placing the SQL into a separate .sql file and then just using start scriptname from the shell can simplify the code especially if any shell script meta-characters like '$' appear in the SQL. Otherwise you have to escape the meta-characters.
    sqlplus /nolog <<EOF
    start script_name
    exit
    EOF
    It is also possible to write the sqlplus script to accept substitution variable from the caller so the line above would look like start script_name $var1 $var2
    HTH -- Mark D Powell --

  • 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 call a procedure from  Shell Script

    Friends,
    How can i call a procedure from a shell script ? If any one know the answer , let me know immediately .
    Thanks in advance .
    Chakks

    We connect using SQLPlus commands on the Unix server:-
    Our code block is below:- We've got DBMS_OUTPUT in the procedure, hence the spooling. You don't need all this, but you do need the sqlplus directory, etc... in your profile.
    sqlplus -s <<EOF > ${CREATE_LOG_FLE}
    $UserName/$Password@$SID
    SET SERVEROUTPUT ON SIZE 1000000;
    spool ${CREATE_LOG_FLE}
    EXECUTE $STORED_PROC(${Months}, ${DeleteRecords});
    EOF
    Hope that helps

  • Unable to see the sql serveroutput from shell script

    Hello experts,
    I have a shell script which I am using to call a pl/sql proc.
    This proc writes to dbms_output.
    I would like to capture the dbms_output to a file when calling sqlplus from my shell script.
    Here is the code:
    ===============================
    echo "
    sqlplus apps/$APPS_PWD << ENDOFSQL
    set serveroutput ON
    set feedback off
    set verify off
    set linesize 250
    set pagesize 250
    begin
    jdr_utils.listcustomizations('$i');
    end;
    exit
    ENDOFSQL
    " >> new.log
    ===============================
    What I get in the 'new.log' is given below:
    ===============================
    sqlplus apps/prj08app << ENDOFSQL
    set serveroutput ON
    set feedback off
    set verify off
    set linesize 250
    set pagesize 250
    begin
    jdr_utils.listcustomizations('/oracle/apps/irc/candidateSelfService/webui/VisVacDispPG');
    end;
    exit
    ===============================
    ENDOFSQL
    What I would like to get is the dbms_output given by the procedure.
    Please suggest.
    Thanks,
    Vinod

    Vinod wrote:
    Hello experts,
    I have a shell script which I am using to call a pl/sql proc.
    This proc writes to dbms_output.
    I would like to capture the dbms_output to a file when calling sqlplus from my shell script.
    Here is the code:
    ===============================
    echo "
    sqlplus apps/$APPS_PWD << ENDOFSQL
    set serveroutput ON
    set feedback off
    set verify off
    set linesize 250
    set pagesize 250
    begin
    jdr_utils.listcustomizations('$i');
    end;
    exit
    ENDOFSQL
    " >> new.log
    ===============================
    What I get in the 'new.log' is given below:
    ===============================
    sqlplus apps/prj08app << ENDOFSQL
    set serveroutput ON
    set feedback off
    set verify off
    set linesize 250
    set pagesize 250
    begin
    jdr_utils.listcustomizations('/oracle/apps/irc/candidateSelfService/webui/VisVacDispPG');
    end;
    exit
    ===============================
    ENDOFSQL
    What I would like to get is the dbms_output given by the procedure.
    Please suggest.
    Thanks,
    VinodYou need to realize & understand that EVERY command line command runs in its own separate OS process.
    So the results from DBMS_OUTPUT get sent to Standard Out for the sqlplus process; which is NOT attached to your terminal.
    The bottom line is you can't get there from here.

  • How to Call pl/sql procedure from shell script

    Hi,
    I've one procedure which takes the xml file name as input from one of the remote location. Every day users keep one file in that location.
    For eg:
    ACS_RPO00020110316_20110316220956.xml
    ACS_RPO00020110319_20110319220956.xml
    I need to read the latest file in this case. In this case second one is the latest file.
    Can some body please help me how to write script to pass parameter to that procedure that via shell program and execute that.
    Thanks in advance.
    Regards
    Nagendra

    hi
    I executed the below mentioned steps, but I did not get any result:
    I am pasting all the steps which I did
    -bash-3.2$ ls -lrt
    total 316
    -rw-r--r-- 1 oratest dba 4884 Mar 16 03:56 XXGEBIZ_EPO160320110356.xml
    -rw-r--r-- 1 oratest dba 4884 Mar 16 03:57 XXGEBIZ_EPO160320110357.xml
    -rw-r--r-- 1 oratest dba 4884 Mar 16 17:52 GEBIZ_ACS_RPO00020110316_20110316175216.xml
    -rw-r--r-- 1 oratest dba 38 Mar 16 18:18 GEBIZ_ACS_RPO00020110316_20110316181858.NODATA
    -rw-r--r-- 1 oratest dba 63 Mar 16 22:09 GEBIZ_ACS_RPO00020110316_20110316220956.xml
    -rw-r--r-- 1 oratest dba 9716 Mar 16 22:14 GEBIZ_ACS_RPO00020110316_20110316221429.xml
    -rw-r--r-- 1 oratest dba 12988 Mar 17 01:42 GEBIZ_POC_RPO000EPO20110317_20110317014247.xml
    -rw-r--r-- 1 oratest dba 13103 Mar 17 01:53 GEBIZ_POC_RPO000EPO20110317_20110317015356.xml
    -rw-r--r-- 1 oratest dba 38 Mar 17 01:57 GEBIZ_POC_RPO00020110317_20110317015712.NODATA
    -rw-r--r-- 1 oratest dba 38 Mar 17 18:44 GEBIZ_ACS_RPO00020110317_20110317184423.NODATA
    -rw-r--r-- 1 oratest dba 12326 Mar 17 18:46 GEBIZ_ACS_RPO00020110317_20110317184603.xml
    -rw-r--r-- 1 oratest dba 67578 Mar 18 01:32 GEBIZ_POF_RPO000EPO20110318_20110318013232.xml
    -rw-r--r-- 1 oratest dba 14484 Mar 18 20:27 GEBIZ_POF_RPO000EPO20110318_20110318202754.xml
    -rw-r--r-- 1 oratest dba 47653 Mar 19 01:29 GEBIZ_PYS_RPO00020110319_20110319012953.xml
    -rw-r--r-- 1 oratest dba 937 Mar 21 09:34 GEBIZ_SUPP.xml
    -rw-r--r-- 1 oratest dba 947 Mar 21 09:35 GEBIZ_SUPP1.xml
    -rwxrwxrwx 1 oratest dba 121 Mar 21 17:43 test
    -bash-3.2$
    -bash-3.2$ cat > test
    ls -lrt | tail -1
    filelist = $(ls GEBIZ_SUPP*.xml)
    for file in $filelist ; do
    echo "inside loop"
    file = $file
    echo "file name " $file
    done
    XGBZ_SUPP_MAST_XMLTAG_PROC $file
    -bash-3.2$ chmod 777 test
    -bash-3.2$ ./test
    -bash: ./test: Text file busy
    -bash-3.2$
    Initially I listed down all the files, in a sample file I've written the steps. But nothing is executed.
    One thing I want to ask here XGBZ_SUPP_MAST_XMLTAG_PROC is my procedure. I think I need to invoke sqlplus in the so as to execute my pl/sql script.
    Gurus, please let me know how to write them.
    Regards
    Nagendra

  • How to execute SQL Instruction from Application Module

    Hi people
    I´d like to know how I can execute a SQL Instruction like "delete from user" from the Application Module ..prepareSession method...
    I´m Using Jdev 10 with ADF Faces
    thank you

    Hello,
    Code example:
    @Override
      protected void prepareSession ( Session session ) {
        super.prepareSession( session );
        setDebugOff();
      private static final String DEBUGOFF = "begin IVA_UI_ALGEMEEN_PCK.SET_DEBUG_OFF; end;";
      public boolean setDebugOff () {
        boolean success = false;
        PreparedStatement debugOffSP = null;
        try {
          debugOffSP = getDBTransaction().createPreparedStatement( DEBUGOFF, 0 );
          success = debugOffSP.execute();
        } catch ( Exception e ) {
          success = false;
        } finally {
          if ( debugOffSP != null ) {
            try {
              debugOffSP.close();
            } catch ( Exception e ) {
              log.warning( e.getMessage() );
        return success;
      }-Anton

Maybe you are looking for

  • Thread unserialized exception: NotSerializableException: java.lang.Thread

    hello experts, i have this exception coming; seems to be coming from some thread but i removed all the threads from my code, i thought its because of some object which is still unserialized, i am not sure whether this is because of one unserialized o

  • Quotes/apostrphies display as question marks

    My WebHelp is run on a Linux server. Most of my apostrophies and quotes are being displayed as question marks. I did discover that when cutting and pasting into RoboHelp, in some cases, causes this problem. The solution being to go to each individual

  • Conditional coloring in table row

    Hi, I want to show some table cells highlighted with some colors.for different condition.For example if status is active then show in green otherwise show in red. How can i achieve ?

  • Mapping superscript 2 and 3 to a key?

    How do I go about if I need to have quick access to superscript ² and ³ (the actual character for these, represented by ² and ³ in HTML entities)? Ideally, I would like to map these 2 characters to Alt+Numpad-2 and Alt+Numpad-3 respectively (for easy

  • My iChat says I don't have a camera on my macbook.  how do I get this turned back on?

    Any one know how to get my camera to be recognized on my Macbook?  It says I don't have a camera installed on my computer.  I'm running Mac OS X 10.5 and I haven't found any fix besides updating my OS.  What are my options...