Calling a sql in shell script

Dear All,
I want to call an sql script within a unix shell script. I want to pass a parameter into the shell script which should be used as a parameter in teh sql script.
e.g
$ ./shell1.sh 5000129
here 5000129 is a prameter
inside shell script i am calling one sql script
e.g.
@script1.sql;
inside the sql script I have an update statement
UPDATE abc set xx = 22 where id = 500129;
as you can see the 5000129 passed as shell script parameter, is being passed as parameter in the sql script.
Please can you advise how can I achieve this?
Many Thanks,

Hi
You could try something like this.
tmpSQLFile=$EXTLOG_DIR/tmpSQLFile_$$.sql
tmpSpoolFile=$EXTLOG_DIR/tmpSpoolFile_$$.sql
export ORACLE_PWD=`cat /home/oracle/secure/runtime_user.dat`
echo "spool $_tmpSpoolFile" > $_tmpSQLFile
echo "SET ECHO OFF NEWP 0 SPA 0 PAGES 0 FEED OFF HEAD OFF TRIMS ON LINESIZE 10000 TIMING OFF" >> $_tmpSQLFile
echo "begin" >> $_tmpSQLFile
echo "DW_MGT_SCHEMA.PKG_RUNTIME_HANDLER.SP_UPD_RUNTIME_EXT_CTL_LOG_TDT(p_transfer_date => '$today', p_schedule_id => $schedule_id);" >> $_tmpSQLFile
echo "end;" >> $_tmpSQLFile
echo "/" >> $_tmpSQLFile
echo "exit" >> $_tmpSQLFile
sqlplus ${ORACLE_USER}@${ORACLE_SID} @$_tmpSQLFile << EOT
`echo $ORACLE_PWD`
EOTCheers
Gary

Similar Messages

  • How to Call Multiple Sessions through Shell scripting

    Dear Members,
    I have a scenario where I load data into target table from 20 different source tables.
    For this I have written three procedures where there exists an bulk insert executed on a same table in every procedure. Now I have to call these procedures simultaneously so that
    all three bulk loads are executed at once in different sessions.
    For this I have to write a shell script which opens 3 different sessions and execute all these packages at once.
    Can you guide me through.

    When you call sqlplus in your shell script, put a & at the end so that it runs the SQL scripts in the background. For instance:
    #!/bin/bash
    ...oracle home stuff
    $ORACLE_HOME/bin/sqlplus user/pass @script.sql &
    $ORACLE_HOME/bin/sqlplus user/pass @script2.sql &
    $ORACLE_HOME/bin/sqlplus user/pass @script3.sql &

  • Sql loader shell scripting

    Hi All,
    I need help on sql loader shell scripting basically since my input file is csv file will load into some target table say xx_90 along defining with control and data file. what where the data that goes into the bad file a segment of scripting that keep watching on badfile directory path if any bad file it finds it should move to a sperate database error table.
    Plz any sqlloader shellscripting experts can provide me the solution for this. Its a very urgent code i need to deliver I need the sample code for this your help is highy appreciated
    thanku
    sahana

    thanku..............when the load fails it moves to bad file script something like filewatcher it sees the data in the badfile and loads into the database error table........as i am basically businessobjects developer as for time being they have assinged me the task i did few manual loading on sql loader but i never have any experince on writing unix scripting i am quite worried to get this script done........
    can i use the samecode for the failed bad records into seperate external table......
    here i would change the path location and the rest goes as it isright............................i have the script for loading the datainto the targetsomething like this:
    sqlldr userid=ops$NGPTQMS/[email protected] \
    control=${evncpaq1/apps/cp/cm/r11.5.10/geae/gl/include/PAY0001_test.ctl} \
    data=${evncpaq1/data/infile/mon_gross_det.dat} \
    log=${evncpaq1/data/infile/mon_gross_det.log} \
    discard=${evncpaq1/data/infile/mon_gross_det.dis} \
    errors=999
    #bad=${BAD_FILE} \
    if [ $? -ne 0 ]; then
    echo "Error ! The sql loader call failed "
    exit 1
    fi
    IF any error is there in the script plz modify it and plz provide the complete code where to incorporate the code which you have written for bad file. Would be set it in seqence the steps so that i can run it in cron tab basically i have no other support for me to assist me on the job.......
    my dba has sent me the mail something like this:
    Please see the attached script to archive the source file once we are done with loading the data to the database. You already have the script for loading the data to the database. Please incorporate the attached script with your loading script. This script is generic and can be used to archive the bad file also once it has been loaded into the database (in case of any failures). This script send an email in case of any failures to the defined email distribution list. Right now the assumption is to run this through the cron. It we need to run this through the Appworx I will have to do some changes in the script. Also we will have to install the appworx agent on the server. Please let me if we need to need to run this through appworx I will create the appworx module for the same.
    and the archive script he sent is:
    . $HOME/.profile
    # Script to Archive SysLog files
    # This script accepts 2 parameters
    # - 1: Script Name          2: File Name
    # Created By : Pravin Darbare
    # Creation Date : 03/19/2008
    # Modified Date :
    # Modification History :
    echo "Starting SysLog_archiving Process"
    # Set Environmental Variables
    echo "Invoke Set Variable Script `date '+%H%M%S'`"
    # Set Local Script Variables
    #SCRIPT_NAME=$1
    SOURCE_DIR=$1
    FILE_NAME=$2
    # Zipping and Archive Source File
    echo "Zip Source file `date '+%H%M%S'`"
    #cp $LOAD_SRC_FILES/$SOURCE_DIR/$FILE_NAME $LOAD_SRC_FILES/syslog/Old_$FILE_NAME
    gzip /$SOURCE_DIR/$FILE_NAME
    check_rtn_status=$?
    if [ $check_rtn_status != 0 ]; then
    echo "Zipping source file Syslog process unsuccessfull"
    mailx -s "Zipping source file during Syslog unsuccessfull" $PR_PAGER_EMAIL_LIST </dev/null
    exit 1
    fi
    echo "Archive Source File `date '+%H%M%S'`"
    mv /$SOURCE_DIR/$FILE_NAME.gz /$SOURCE_DIR/archive/$FILE_NAME.gz$FILE_EXT
    check_rtn_status=$?
    if [ $check_rtn_status != 0 ]; then
    echo "Archiving source file during Syslog load process unsuccessfull"
    mailx -s "Archiving source file during Syslog load process unsuccessfull" $PR_PAGER_EMAIL_LIST </dev/null
    exit 1
    fi
    # example of calling file Syslog_archiving_Files.sh /apps/syslog/source_dir a.txt
    # example of calling file (Bad file) Syslog_archiving_Files.sh /apps/syslog/source_dir_bad a.txt
    # You need to have directory "archive" in both pathes .
    based on the complete detailed mail must having some view plz provide me something like exact code the rest path directories i will change it........
    for me its highly urgent to keep up my job
    Your support is highly appreciated
    Thanks&Regards
    sahana

  • Calling HTML File in Shell Script.

    Hi
    I have a shell script and a HTML file.
    HTML file is to create a Table.
    the HTML Script is as follows
    <html>
    <body>
    <table border="1">
    <tr>
    <td>Requisition Number</td><td>$PARAM0</td>
    </tr>
    <tr>
    <td>Purcahse Order Number</td><td>$PARAM4</td>
    </tr>
    <tr>
    <td>Purchase Line Number</td><td>$PARAM5</td>
    </tr>
    <tr>
    <td>Hold Reason</td><td>$PARAM3</td>
    </tr>
    <tr>
    <td>Hold Date</td><td>$PARAM2</td>
    </tr>
    </table>
    </body>
    </html>
    The output of this HTML file is a table with 5 rows and 2 columns.
    I saved this file as mail.html and placed it in the server where i have placed the Shell Script.
    When i call this HTML in Shell Script ... as follow
    cat /FND_TOP/bin/mail.html
    the output is not the table but infact the html tags are displayed.
    I need the table when i run this shell script.
    It would be of great help if anyone has a good solution for this.
    Thanks in Advance

    First, you need to put the file where your httpd server (you will need apache running) can find it. This is usually some place like:
    /var/www/html/table.htmlThen use a text-mode browser as Frits suggested to render it so your script can read it:
    #!/bin/sh
    lynx -dump http://localhost/table.html | while read row; do
        echo "${row}"
    doneor how ever you want to process the data.
    Another approach is to use XML transformations. First write an XML stylesheet:
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="http://www.w3.org/2005/02/xpath-functions" version="1.0">
         <xsl:output indent="no" method="text" standalone="yes" version="1.0"/>
         <xsl:template match="*">
              <xsl:apply-templates/>
         </xsl:template>
         <xsl:template match="td">
              <xsl:text> </xsl:text>
              <xsl:value-of select="normalize-space()"/>
         </xsl:template>
    </xsl:stylesheet>and then run your HTML through the {font:Courier}xsltproc{font} processor:
    $ xsltproc table.xsl table.html
    Requisition Number $PARAM0
    Purcahse Order Number $PARAM4
    Purchase Line Number $PARAM5
    Hold Reason $PARAM3
    Hold Date $PARAM2To be neat, I have omitted the many blank lines that were also output.
    HTH

  • How we can call or execute a SHELL script through Oracle forms or Reports

    How we can call or execute a SHELL script through Oracle forms or Reports.Its urgent.......

    Use HOST command.

  • Can I call host file ( Unix Shell script ) from Oracle 10g trigger

    Hi,
    I am new to Oracle 10g. Can I call host file ( unix shell script ) from Oracle 10g trigger ?. I know it is possible. Pl explain me with small example
    thanks & regards
    parag

    user12009546 wrote:
    Hi,
    I am new to Oracle 10g. Can I call host file ( unix shell script ) from Oracle 10g trigger ?. I know it is possible. Pl explain me with small example
    thanks & regards
    paragIf you are in 10g, you can simple call shell script from DBMS_SCHEDULER:
    BEGIN
    DBMS_SCHEDULER.CREATE_JOB (
    job_name => 'TEST_SCRIPT',
    job_type => 'EXECUTABLE',
    job_action => 'PATH_OF_YOUR_SCRIPT',
    start_date => SYSDATE,
    repeat_interval => 'FREQ=MINUTELY; INTERVAL=1',
    enabled => TRUE,
    comments => 'Shell script from Oracle'
    END;
    /

  • Calling sql through shell script

    How do i call a sql file through shell script in unix ?

    Rahul India wrote:
    export ORACLE_HOME=$ORACLE_BASE/product/10g
    cd $ORACLE_HOME
    set `sqlplus -s <SCHEMA_NAME>/<SCHEMA_PASSWORD> <<EOF
    @r_100.sql
    exit;   
    EOF`THIS SCRIPT IS OK?You'll also need to set ORACLE_SID
    And I don't know why everyone is putting the reference to sqlplus inside a "set" valuation, nor why they are putting the reference to the script in a redirected input stream. All you need is
    sqlplus -s user/password  @r_100.sqlAnd to insure the invironment is correctly set:
    export ORACLE_SID=whatever
    export ORAENV_ASK=NO
    . oraenv
    unset ORAENV_ASK=NO
    sqlplus -s user/password  @r_100.sql

  • PL/SQL using Shell Script

    Hi,
    I want to study in details about how to use shell script in pl/sql codes. Can any one suggest some useful link on the same.
    Nordik

    smon wrote:
    BluShadow wrote:
    miriam_omaha wrote:
    If you mean execute a shell script from a procedure, there are ways, not easy ways, to execute a shell script - try this thread on that topic:Not easy?
    What's not easy about setting up a job using DBMS_SCHEDULER which can directly call any executable at the operating system level?that doesn't meet the requirement, it's about executing host commands from within plsql.Which you can do with DBMS_SCHEDULER by creating a job to execute straight away. DBMS_SCHEDULER can execute operating system commands...
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_sched.htm#i1010013
    >
    'EXECUTABLE'
    This specifies that the program is external to the database. External programs implies anything that can be executed from the operating system's command line. AnyData arguments are not supported with job or program type EXECUTABLE.

  • Passing variable from sql to shell script

    Usually we can pass arguments from shell script to the sql that us called inside the shell script. But I also want to do the reverse. I have the location of my backup path in a table. I want to run the rman script (shell), read this parameter from the table and use this to construct the "format" path in rman. Anyone has any ideas about this. Thanks.

    To achieve getting the modified value from the table everytime the job runs, I encapsulated this in another job.
    BEGIN
    DBMS_SCHEDULER.CREATE_JOB(
    JOB_NAME           => 'TEST_LOGS_MAIN',
    JOB_TYPE             => 'PLSQL_BLOCK',
    JOB_ACTION          => 'declare
    v_aname varchar2(32);
    begin
    select aname into v_aname from attr where attrid = 3;
    DBMS_SCHEDULER.CREATE_JOB(
    JOB_NAME        => ''TEST_LOGS'',
    JOB_TYPE        => ''EXECUTABLE'',
    JOB_ACTION      => ''/opt/sql/testy.sh'',
    number_of_arguments => 1,
    COMMENTS        => ''TEST'');
    dbms_scheduler.set_job_argument_value(''TEST_LOGS'',1,v_aname);
    dbms_scheduler.enable(''TEST_LOGS'');
    end;',
    REPEAT_INTERVAL => 'FREQ=MINUTELY',
    ENABLED           => TRUE);
    END;
    /

  • Loading incomplete using sqlplus_exec_template.sql  in shell script

    Hi,
    I've tried to automate the dataloading by calling sqlplus_exec_template.sql for each mapping in the shell script bash. (I comment out the last exit line in the script). But the loading were always partially complete for those that take longer time, says more than 5 or 10min. I've also tried to call each mapping in different shell and got the same result. How do you work around this? Below is part of the lines in my shell script. Thanks.
    sqlplus -s test_rta/test_rta << EOF
    @sqlplus_exec_template.sql 'TEST_RTR' 'TEST_LOC' 'PLSQL' 'CONSOL_SUP_MAP' ',' ','
    @sqlplus_exec_template.sql 'TEST_RTR' 'TEST_LOC' 'PLSQL' 'CONSOL_PART_MAP' ',' ','
    EOF

    I 've tried to use :
    sqlplus username/[email protected] @C:\OWB\owb\rtp\sql\sqlplus_exec_template.sql
    rtschema OWBLOCATION SQL_LOADER CRD_APPL_MAPPING "," ","
    where OWBLOCATION I have used the deploy location of the mapping for my case, created within OWB. The value is CCS_DEPLOY.
    But the error is the same :
    ======================================================
    Stage 1: Decoding Parameters
    | location_name=CCS_DEPLOY
    | task_type=SQL_LOADER
    | task_name=CRD_APPL_MAPPING
    Stage 2: Opening Task
    declare
    ERROR at line 1:
    ORA-20001: Task not found - Please check the Task Type, Name and Location are
    correct.
    ORA-06512: at line 261
    ========================================================
    could you tell me the SQL used by WB_RT_API to get the task from runtime schema. So that I could check the correct location myself.
    Or how could I view the pl/sql of WB_RT_API_EXEC which is wrapped.
    Thx for your help.
    Rg.
    CH

  • Embed SQL in shell script

    I'm trying to embed sql statements in shell.
    I'm new to this..
    Can someone please pass some relevant document links on the web which demonstrates it?
    What I'm looking for is:
    1) How to pass variables from shell environment to sql
    2) How to pass values back to the shell from sql
    Example:
    Say, I want to run a concurrent request ( inside a shell script) . Then I want to check the status of this concurrent requests from FND_CONCURRENT_REQUESTS
    For which I have do a:
    #/bin/bash
    #Submit the request
    CONCSUB APPS/APPS SYSADMIN 'System Administrator' SYSADMIN CONCURRENT FND FNDSCURS >> /tmp/${TWO_TASK}request.log
    #Here, I pull out the value of request id from the log #in v_request_no
    v_request_no=`cat /tmp/${TWO_TASK}request.log | cut -d" " -f3`
    echo "Submitted request No: ${v_request_no}"
    Now, I want to check the status of this request, for which I want to embed the sql:
    select status_code from FND_CONCURRENT_REQUESTS where request_id=${v_request_id}
    How do I embed this?
    And later, I want to pass the value of "status_code" back to my shell and do some manipulation.
    How do I get the value ( of status_code) back in shell script?
    I did a quick hunt on the google to find a relevant doc. No luck yet, so I thought I'll post it here and then go back to some more hunting.
    Message was edited by:
    itzz.me

    Replying to myself instead of editing previous post. Confusing either way, hopefully I picked the less-confusing route.
    The second script snippet that I posted would work really well except for one tiny detail: exit codes have to be numeric. The status_code column in FND_CONCURRENT_REQUESTS is certainly not numeric. :-)
    Here's something that should work. I even checked it for syntax this time, because, well, it's really ugly. :-) Needless to say, you'll need to modify it slightly to plug into your script, since I hard-coded a requestid for purposes of illustration. Please note that the sqlplus command in the here document is enclosed in backticks, not single quotes:
    ----begin code snippet---
    #!/bin/bash
    v_request_id=2415616 #Just an example, sub your own value here
    status_code=`sqlplus -s apps/appspass<<EOF | grep Code | cut -f2 -d:
    select 'Code:' || status_code
    from fnd_concurrent_requests
    where request_id = $v_request_id;
    exit;
    EOF`
    echo "Status code is: $status_code"
    ----end code snippet-------
    If you can't pass in the apps password from the environment, and have to hard-code a password into the script (yecccchhh), I'd suggest setting up a read-only user with SELECT privileges on FND_CONCURRENT_REQUESTS, and running sqlplus as the read-only user instead of apps.

  • 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

  • Capturing Users with running sql in shell script after every 10min

    Hi All,
    we have a strange prob. of database crash, therefore decided to check what users do when OS/DB crashes,
    i need your input in RUNNING/SCHEDULING such a script which gathers all active users with running SQL and append in a logfile so that we are aware of what happened when DB/OS Crashed.
    i can run this run a query from V$SESSION,V$SQL, and V$PROCESS but i need your input writing such a SHELL Script and scheduling can run by CRON.
    Regards.

    Here ya go.
    (Assuming you want a script to run against one sid)
    script:
    #!/bin/ksh
    # Set environment
    . $HOME/.profile
    export ORACLE_SID=your sid
    sqlplus <<! > /some_report_file
    / as sysdba
    sql you want to execute here*
    exit
    cron entry:
    0,5,10,15,20,25,30,35,40,45,50,55 * * * * /your/script/name/here > /dev/null 2>&1

  • Calling Procedure/Package in shell script

    how to call a package / procedure in a unix shell scripts. also how to schedule jobs in shell scripts.

    That's usually accomplished by run sqlplus from shell script.
    http://www.oracle-base.com/articles/misc/OracleShellScripting.php
    Crontab can be used to schedule jobs in unix.
    http://www.adminschoice.com/docs/crontab.htm

  • Calling sqlplus from unix shell script

    Hi All,
    I am executing the following code :-
    sqlplus -s ${DATABASE_USER} |&
    print -p -- 'set feed off pause off pages 0 head off veri off line 500'
    print -p -- 'set term off time off serveroutput on size 1000000'
    print -p -- "set sqlprompt ''"
    print -p -- "SELECT run_command from tmp_run_batch where upper(batch_name) = upper('${PAR_PROGRAM_NAME}');"
    read -p RUN_COMMAND
    eval print -p -- \""execute dbms_output.put_line(${RUN_COMMAND});"\"
    read -p RET_VAL
    print -p -- "exit;"
    The select stmt given above gives sample output as :-
    pack_claims_clas_utils.func_main('$PAR_RUN_DATE','$PAR_RUN_LEVEL','$PAR_EXCLUSIVE_RUN_YN')
    And then this package is executed.
    The problem that I am facing is how to handle the no_data_found case of the select stmt. . When this case arises then the stmt. "read -p RUN_COMMAND" hangs.
    Could you please provide any solution ?
    Thanks
    Suds

    Hi,
    Have you tried this:
    # if [ -n means String has non-zero length
    if [ -n $RUN_COMMAND ]
    read -p RUN_COMMAND
    fi
    Hi All,
    I am executing the following code :-
    sqlplus -s ${DATABASE_USER} |&
    print -p -- 'set feed off pause off pages 0 head off veri off line 500'
    print -p -- 'set term off time off serveroutput on size 1000000'
    print -p -- "set sqlprompt ''"
    print -p -- "SELECT run_command from tmp_run_batch where upper(batch_name) = upper('${PAR_PROGRAM_NAME}');"
    read -p RUN_COMMAND
    eval print -p -- \""execute dbms_output.put_line(${RUN_COMMAND});"\"
    read -p RET_VAL
    print -p -- "exit;"
    The select stmt given above gives sample output as :-
    pack_claims_clas_utils.func_main('$PAR_RUN_DATE','$PAR_RUN_LEVEL','$PAR_EXCLUSIVE_RUN_YN')
    And then this package is executed.
    The problem that I am facing is how to handle the no_data_found case of the select stmt. . When this case arises then the stmt. "read -p RUN_COMMAND" hangs.
    Could you please provide any solution ?
    Thanks
    Suds

Maybe you are looking for

  • I tried to download the the latest itunes on my older computer but ultimately received an error message for a failed temp folder...pls. help

    I am trying to download itunes 10 on to my older computer that currently has itunes 8.  It works it way through most of the install process but ultimately notes "there was an error creating a temporary file necessary to complete this installation." 

  • Help something is not right!!!! Please email me!

    I have tried to connect my ipod, with a standard ipod cable, to my tv and the picture is in black and white and the picture continuously rolls. I have tried different tv's and even a different cable but no luck. What am I doing wrong? Settings are al

  • Iphoto and Itunes not responding after an Apple Software Update

    Hi Afew days ago I did the Apple Software Update and since then I haven't been able to get onto my Itunes or Iphoto, both of which I use quite often. Itunes just doesn't load at all and Iphoto starts to open the page but then that multicoloured ball

  • Download EBS 12.1.3

    Hi All, Can I download EBS 12.1.3 from edelievery.oracle.com. On Edelivery 12.1.1 is avlable. Or do I need to apply patches on 12.1.1 to increase path level to 12.1.3 Thanks,

  • Geforce GTX 980 TI

    Aspire Acer G3 605 PredatorGPU: GeForce GTX 980CPU: intel(R) Core(TM) i5-4590 CPU @ 3.30GHzMemory: 12.00 GB RAM (11.92 GB Usable)Current Resolution: 1920 x 1080, 30HzDriver Version: 353.30Operating System: Microsoft Windows 8.1 Pro I am pretty sure i