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

Similar Messages

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

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

  • Stored Proc Execution through OS command using shell script

    Hi All,
    I have a requirement of executing one stored procedure before putting data in Table through JDBC adaptor and two stored procedures after that.
    I was thinking to write a shell script and execute it before and after message processing in adaptor.
    Can anybody please tell me how should i write a shell script for it?
    I have identified that exec <Stored_Proc_Name> is the syntax for it.
    Will i need to write something more in this script?
    Thanks,
    Atul

    Hi Atul,
    Stored procedures are written on the Database server for which you are going to write JDBC adapter.
    you will just call the storedprocedure in to your adapter.
    as per your requirement you shd run one stored procedure (let us say SP1) and then you have to push data into tables and then run SP2 and SP3...
    so for this write three stored procedures and call them into another SP. in this SP you call SP1 first then insert statement to insert data into tables and then SP2 and SP3.
    finally call SP into your JDBC adapter.
    you can call SP1 in SP as below
    Var_SQL :='call SP1 (''' || Var_1 || ''',''' || Var_2 ||''')' ;
    EXECUTE IMMEDIATE Var_SQL;
    i think for this shell script is not required.. correct me if i am wrong...
    Regards,
    Sukarna.

  • How to get return code or parameters from PL/SQL in my shell script ?

    My shell script must check the result of PL/SQL's running, and decide what to do in the next step.

    I think you put the problem the wrong way.
    You should try to do as much as possible through your SQL scripts, and, if you need to make OS calls, you may do that using host(command_string).
    If you need to transfer parameters from other programs to your FORMS (PL/SQL), then you have to see user_exit.
    Some other means would be to have your PL/SQL write to certain OS files that the shell script may read, but that doesn't seem like good practice to me.

  • Pl/sql procedure with shell script

    Hi Guys,
    I will be updating some of the columns in the database thru SQL UPDATE stament. I want to make this process automatic. I.e instead of running manually this uodate process, i want to write a unix script which run on cron job. In the update stament I have to compare date like e_create_date > to_date (........, 'yymmdd') and date should be 2 days previous then to date and I would ike to create the spool file which I would like to send through mail.the script will run automatically.
    I am confused how to write shell script & sql procedure and how to call it inside the shell script. How can this be done.
    Help Appreciated.
    Thanks
    sonu

    save the Store procedure as a create_SP.sql in OS
    save another testrun.sql
    as follows
    begin
    sp_test('&p_test');
    end;
    If you are on a Unix or Solaris OS then
    open a Shell Script as follows :
    and name as test.sh or test.ksh
    var='SYSTEM'
    export var
    sqlplus username/password
    @create_SP.sql
    -- this created a store procedure on the database
    @testrun.sql $var
    This will execute the SP with parameter from OS Variable.

  • SQL LOADER and SHELL SCRIPT ISSUE

    Hello Guys,
    I know this not the right forum but i am not sure where i should post this.
    Pelase help
    I am running a shell script which is giving me error
    Username:SQL*Loader-128: unable to begin a session
    ORA-01017: invalid username/password; logon denied
    SQL*Loader: Release 10.2.0.4.0 - Production on Thu Nov 19 13:02:04 2009
    Copyright (c) 1982, 2007, Oracle.  All rights reserved.
    SQL*Plus: Release 10.2.0.4.0 - Production on Thu Nov 19 13:02:06 2009
    Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.
    Enter user-name:
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL>
    0 rows updated.
    Commit complete.
    SQL> SQL> Disconnected from Oracle Database 10g Enterprise Edition
    SQL> SQL> Release 10.2.0.4.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options Thu Nov 19 13:02:06 EST 2009In shell script i have used the same username and passwd which i am using from command line
    the shell script is calling sql loader to load file
    and for that also the username and passwd is same.
    i am able to run sqlldr command from command line dont knw why here its giving error
    here is my shell script
    set -a
    . $HOME/.edw.env
    . $admlib/checklib.sh
    LOGDIR=$admsrc/sigma6/ppadala/copg
    LOGFILE=${LOGDIR}/log/test`date '+%m%d'`.xtr
    DB_USER=copg
    DB_PWD=copg
    set +a
    cd $LOGDIR
    if test ! -f $admsrc/sigma6/ppadala/copg/DM_Daily_EFolderCloseCancel_Report_11192009.txt
    then
       echo "Error: DM_Daily_EFolderCloseCancel_Report_11192009.txt does not exist and/or is not a regular file." >> ${LOGFILE}
       exit 1
    fi
    echo 'End of Checking for the existence of the file - Successful'>> ${LOGFILE}
    sqlldr control=$admsrc/sigma6/ppadala/copg/Close_Cancle.ctl log=$admsrc/sigma6/ppadala/copg/Close_cancle.log
    userid=${DB_USER}/${DB_PWD} silent=\(HEADER,FEEDBACK,DISCARDS\)>> ${LOGFILE} 2>&1
    case $? in 0) :;;1|3) echo "Error: SQL Loader" >> ${LOGFILE}
         exit 1;;
    esac
    sqlplus << EOD
    ${DB_USER}/${DB_PWD}
    @Close_Cancle.sql
    EOD
    if [ $? -ne 0 ]
    then
        echo "Error: SQL Plus for script Processing" >> ${LOGFILE}
        echo "Resi Unit Scheduling Report Refresh failed" >> ${LOGFILE}
    fi
    ) > ${LOGFILE} 2>&1
    echo `date` >> ${LOGFILE}
    if [ -f ${LOGFILE} ]
    then
    mail -s "Resi Unit Scheduling" "[email protected]" < ${LOGFILE}
    sleep 3
    `ck_error ${LOGFILE}`
    fiplease help guys
    thanks

    Thanks for the reply
    In Close_cancle.log also its the same msg which i posted.
    logon denied..............
    and this is the log file contents when i do set - X on
    + cd /u2144009/src/sigma6/ppadala/copg
    + test ! -f
    + /u2144009/src/sigma6/ppadala/copg/DM_Daily_EFolderCloseCancel_Report_1
    + 1192009.txt echo End of Checking for the existence of the file -
    + Successful
    + 1>> /u2144009/src/sigma6/ppadala/copg/log/test1119.xtr
    + sqlldr control=/u2144009/src/sigma6/ppadala/copg/Close_Cancle.ctl
    + log=/u2144009/src/sigma6/ppadala/copg/Close_cancle.log
    Username:SQL*Loader-128: unable to begin a session
    ORA-01017: invalid username/password; logon denied
    SQL*Loader: Release 10.2.0.4.0 - Production on Thu Nov 19 17:32:17 2009
    Copyright (c) 1982, 2007, Oracle.  All rights reserved.
    + userid=copg/copg silent=(HEADER,FEEDBACK,DISCARDS)
    + 1>> /u2144009/src/sigma6/ppadala/copg/log/test1119.xtr 2>& 1
    + :
    + sqlplus
    + 0<<
    copg/copg
    @Close_Cancle.sql
    SQL*Plus: Release 10.2.0.4.0 - Production on Thu Nov 19 17:32:58 2009
    Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.
    Enter user-name:
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL>
    0 rows updated.
    Commit complete.
    SQL> SQL> Disconnected from Oracle Database 10g Enterprise Edition
    SQL> SQL> Release 10.2.0.4.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    + [ 0 -ne 0 ]
    Thu Nov 19 17:32:59 EST 2009Edited by: user10647455 on Nov 19, 2009 2:35 PM

  • How to pass a result of SQL query to shell script variable

    Hi all,
    I am trying to pass the result of a simple SQL query that only returns a single row into the shell script variable ( This particular SQL is being executed from inside the same shell script).
    I want to use this value of the variable again in the same shell scirpt by opening another SQL plus session.
    I just want to have some values before hand so that I dont have to do multiple joins in the actual SQL to process data.

    Here an example :
    SQL> select empno,ename,deptno from emp;
         EMPNO ENAME          DEPTNO
          7369 SMITH              20
          7499 ALLEN              30
          7521 WARD               30
          7566 JONES              20
          7654 MARTIN             30
          7698 BLAKE              30
          7782 CLARK              10
          7788 SCOTT              20
          7839 KING               10
          7844 TURNER             30
          7876 ADAMS              20
          7900 JAMES              30
          7902 FORD               20
          7934 MILLER             10
    14 rows selected.
    SQL> select * from dept;
        DEPTNO DNAME          LOC
            10 ACCOUNTING     NEW YORK
            20 RESEARCH       DALLAS
            30 SALES          CHICAGO
            40 OPERATIONS     BOSTON
    SQL> exit
    Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
    $ cat my_shell.sh
    ### First query #####
    ENAME_DEPTNO=`sqlplus -s scott/tiger << EOF
    set pages 0
    select ename,deptno from emp where empno=$1;
    exit
    EOF`
    ENAME=`echo $ENAME_DEPTNO | awk '{print $1}'`
    DEPTNO=`echo $ENAME_DEPTNO | awk '{print $2}'`
    echo "Ename         = "$ENAME
    echo "Dept          = "$DEPTNO
    ### Second query #####
    DNAME_LOC=`sqlplus -s scott/tiger << EOF
    set pages 0
    select dname,loc from dept where deptno=$DEPTNO;
    exit
    EOF`
    DNAME=`echo $DNAME_LOC | awk '{print $1}'`
    LOC=`echo $DNAME_LOC | awk '{print $2}'`
    echo "Dept Name     = "$DNAME
    echo "Dept Location = "$LOC
    $ ./my_shell.sh 7902
    Ename         = FORD
    Dept          = 20
    Dept Name     = RESEARCH
    Dept Location = DALLAS
    $                                                                           

  • SQL Query in Shell script

    Hi everyone,
    I am facing a difficulty in writing a query for a table REF_PRODUCT having some columns like OFFER, PROVIDERID.
    The problem statement is
    if the OFFER not in ('A','B','C') then x='D'
    if x is empty then
    if providerid in (some values) then x='A'
    else if providerid in (some other values) then x='B'
    else x='C'
    where x is a variable in shell script.
    I want to execute the above in shell script. how to manage this?
    Please help..
    Regards
    Abhi

    user8744860 wrote:
    I am facing a difficulty . . . Etc . . .
    I want to execute the above in shell script. how to manage this?
    Please help..
    1) What you posted is not a shell script.
    2) In order for us to help you with your question, you need to post a working test case: create table and insert statements
    as well as the expected result from that data. Provide also an explanation of the rules that lead to this result.
    3) Also provide any code you have written.
    :p

  • PL/SQL function - unix shell script

    Hello,
    I have an application that calls a unix shell script This unix shell script calls a oracle function in the PL/SQL package. For example,
    In package pkg_test, there is function f_test. This function returns pls_interger.
    How can I write a unix shell script to return the value from the oracle function, so that the application can get the value from the unix shell script?
    Many thanks.

    Thank you for your response.
    The Oracle functuion pkg_name.proc_name will return different values, 0, 1, 2, 3 in diffefrent conditions.
    The unix script, myscript.ksh calls pkg_name.proc_name.
    The other application will call myscript.ksh and this application will need to get the values 0, 1, 2, 3 from myscript.ksh.
    Can we make it without using the unix shelll function?
    Thanks.
    Edited by: slsam01 on Jun 2, 2009 9:21 PM

  • Passing params from SQL file to Shell Script and then from Shell to SQL Fil

    Afternoon guys,
    Have a fun question for all you gurus in shell scripting out there. I have a shell script that is calling 2
    different SQL programs. My objective is to pass a variable called request_number from one sql program
    to the shell script and then from the shell script back to another SQL program. I will explain why I
    need this to happen.
    Here is what the shell script looks like which calls sql programs student_load_a.sql and
    student_load_b.sql. Student_load_a.sql basically creates the control file (.ctl) which is needed for the
    SQL*Loader and then student_load_b.sql reads the table that was just loaded and does the main
    processing. My main objective here is to be passing the request_number which is being generated
    using an Oracle Sequence in student_load_a.sql and using this generated number in my main
    processing in student_load_b.sql to select records from the table based on request_number.
    Any ideas ?Any help or recommendations is welcome and appreciated.
    *1. Shell Script*
    # Accept system input parameters
    p_user_id=$1
    p_job_id=$2
    # Create control files for sqlload
    sqlplus.exe -s $p_user_id @$STUDENT_PATH/student_load_a.sql $p_job_id
    exit_status=$?
    # Do sqlloads
    sdesqlldr.exe userid=$p_user_id control=student_load-$p_job_id.ctl \
                                                 log=student_load-$p_job_id.log \
                                                 bad=student_load-$p_job_id.bad
    exit_status=$?
    # Main processing
    # sqlplus.exe -s $p_user_id @$STUDENT_PATH/student_load_b.sql $p_user_id $p_job_id $p_request_number
    sqlplus.exe -s $p_user_id @$STUDENT_PATH/student_load_b.sql $p_user_id $p_job_id
    exit_status=$?
    exit 0*2. student_load_a.sql (Would like to pass back the Sequence Number back to shell script and then use in student_load_b.sql*
    -- Accept system input parameters
    define p_job_id = &1
    spool student_load-$p_job_id.ctl
    select
    'append into table TMP_STUDENT_LOAD
    FIELDS TERMINATED BY '','' optionally enclosed by ''"''
    trailing nullcols
    (request_number CONSTANT ' || '''' || request_number_seq.nextval || ''',
    student_id)'
    from   dual
    spool off;
    exit 0;
    {code}
    *3. student_load_b.sql (This is a big file so I am only adding code that is relevant for the SQL)*
    {code}
    declare
      v_request_number    number(6);
      v_student_id                  number(7);
      cursor cur_student_load is
        select  student_id
        from   TMP_STUDENT_LOAD
        where  request_number = v_request_number
        order by 1;
    begin
        v_user_id := '&1';
        v_job_id := &2;
        -- This is the variable I would like to be be passing from shell script to student_load_b.sql
        -- v_request_number = '&3';
         open  cur_student_load;
         fetch cur_student_load into v_student_id;
          exit when cur_student_load%notfound;
          .... more logic of if then else in here
         close cur_student_load;
    end;
    {code}
    Edited by: RDonASnowyDay on Jan 29, 2010 4:03 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    How come you are mixing WinDoze script (*.exe) with Unix?
    You are aware that you will be passing the password along with the user id to the second sql script?
    I will assume Unix ksh:
    # Accept system input parameters
    p_user_id=$1
    p_job_id=$2
    # Create control files for sqlload
    p_seqno=`sqlplus -s $p_user_id @$STUDENT_PATH/student_load_a.sql $p_job_id`
    exit_status=$?
    # Do sqlloads
    sqlldr userid=$p_user_id control=student_load-$p_job_id.ctl \
           log=student_load-$p_job_id.log \
           bad=student_load-$p_job_id.bad
    exit_status=$?
    # Main processing
    # sqlplus -s $p_user_id @$STUDENT_PATH/student_load_b.sql $p_user_id $p_job_id $p_request_number
    sqlplus -s $p_user_id @$STUDENT_PATH/student_load_b.sql \
               $p_user_id $p_job_id $p_seqno
    exit_status=$?
    exit 0And the first sql script would look like this:
    -- student_load_a.sql
    -- Accept system input parameters
    set echo off pages 0 feed off lin 80 trims on ver off
    def p_job_id = &1
    col seqno NEW_VALUE seqno
    select request_number_seq.nextval seqno from dual;
    set term off
    spool student_load-$p_job_id.ctl
    select
    'append into table TMP_STUDENT_LOAD
    FIELDS TERMINATED BY '','' optionally enclosed by ''"''
    trailing nullcols
    (request_number CONSTANT ''&&seqno'',
    student_id)'
    from   dual
    spool off;
    exit 0;
    {code}
    :p                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • 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 call a FoxPro .prg file through SQL statement

    I created a program exclusive.prg which basically consisted of the statement USE my table exclusive. How can i call this function through a SQL statement using java

    Hi,
    Thank you for he reply.
    Runtime.getRuntime().exec(..)works fine with .exe files.
    but, when a foxpro program file(.prg) is compiled, a (.fxp) file is produced and not a .exe file
    when i write some thing like
    statement.execute("exclusive.fxp")i'm getting an error. here is the stack trace
    java.sql.SQLException: [Microsoft][ODBC Visual FoxPro Driver]Syntax error or access violation
         at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
         at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
         at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(Unknown Source)
         at sun.jdbc.odbc.JdbcOdbcStatement.execute(Unknown Source)
         at excel.TestMom.main(TestMom.java:28)i also tried using
    statement.execute("do exclusive.fxp") and
    statement.execute("do exclusive.prg")I got the same error.
    Dont know what else to do.Can you please suggest some way to work around.

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

  • PL/SQL how to loop thru SQL statement?

    Hey guys. I have this bit of a complicated problem.
    I have a cursor that selects a DISTINCT field called Term and a StudentID.
    I am looping thru that cursor.
    Inside that loop I have another SQL statement that is pulling all rows from the DB where the Term = the Term and the StudentID= the StudentID from the crusor loop.
    My problem is how do I get all the information/rows returned from that SQL statement? I need to loop thru it somehow, but I am not sure how to do it.
    If there is a better way to get this done feel free to chime in.
    Here is my code.
    /* CURSOR*/
    CURSOR c_GPAPerTerm IS
            SELECT DISTINCT Term, Student_ID FROM course_grades
            WHERE STUDENT_ID = p_StudentID;
                 /* OPEN AND LOOP THRU CURSOR*/
        OPEN c_GPAPerTerm;
        LOOP
        FETCH c_GPAPerTerm INTO v_Terms,v_StudentID;
                /* SQL STATEMENT NEED TO LOOP THRU AND GET VALUES FOR EACH ROW*/
                SELECT Score
                INTO v_Scores
                FROM course_grades
                WHERE Term = v_Terms and StudentID = v_StudentID;
        EXIT WHEN c_GPAPerTerm%NOTFOUND;
        END LOOP;
        CLOSE c_GPAPerTerm;

    Ok here's my complete code....it's pretty big though...hope it's not too confusing.
    It compiles fine if I take the new cursor out, so the error is somewhere in that cursor.
    CREATE OR REPLACE PROCEDURE get_Student_GPA(p_StudentID IN NUMBER) AS
         /*VARIABLES*/
         v_Terms VARCHAR2(6);
         v_Courses VARCHAR2(6);
         v_Scores NUMBER;
         v_Grade CHAR;
         v_GPA NUMBER;
         v_ScoresTotal NUMBER :=0;
         v_StudentID NUMBER;
         /*CURSORS*/
         CURSOR c_GetTerms IS
              SELECT Term
              FROM course_grades
              WHERE STUDENT_ID = p_StudentID;
         CURSOR c_GetCourseAndGrade IS
              SELECT Course_ID, Score FROM course_grades
              WHERE STUDENT_ID = p_StudentID;
         CURSOR c_GPAPerTerm IS
              SELECT DISTINCT Term, Student_ID
              FROM course_grades
              WHERE STUDENT_ID = p_StudentID;
         CURSOR c_GetScores (p_Term VARCHAR2, p_StudentID NUMBER) IS          
                   SELECT Score
                   FROM course_grades
                   WHERE Term = p_Term AND StudentID = p_StudentID;
         /*FUNCTIONS*/
         FUNCTION convert_grade(p_GradeNumber IN NUMBER)
              RETURN CHAR IS
         BEGIN
              /* GET NUMERIC GRADE AND CONVERT TO LETTER */
              CASE
                   WHEN p_GradeNumber < 60 THEN RETURN 'F';
                   WHEN (p_GradeNumber > 59  AND p_GradeNumber < 70) THEN  RETURN 'D';
                   WHEN (p_GradeNumber > 69  AND p_GradeNumber < 80) THEN  RETURN 'C';
                   WHEN (p_GradeNumber > 79  AND p_GradeNumber < 90) THEN  RETURN 'B';
                   WHEN (p_GradeNumber > 89  AND p_GradeNumber < 101) THEN RETURN 'A';
              ELSE    RETURN 'Z';
              END CASE;
         END convert_grade;
         FUNCTION calculate_gpa(p_TotalHourPoints IN NUMBER, p_TotalHours IN NUMBER)
              RETURN NUMBER IS
              /*CREATE VARIABLE TO HOLD GPA*/
              v_GPA NUMBER;
         BEGIN
              /*CALCULATE AND OUTPUT GPA*/
              v_GPA := p_TotalHourPoints/p_TotalHours;
              RETURN v_GPA;
         END calculate_gpa;
         FUNCTION calculate_point (p_Grade IN CHAR)
              RETURN NUMBER IS
         BEGIN
              /* GET LETTER GRADE AND CONVERT TO NUMBER */
              CASE
                   WHEN p_Grade = 'A' THEN RETURN 4;
                   WHEN p_Grade = 'B' THEN RETURN 3;
                   WHEN p_Grade = 'C' THEN RETURN 2;
                   WHEN p_Grade = 'D' THEN RETURN 1;
                   WHEN p_Grade = 'F' THEN RETURN 0;
              ELSE    RETURN 0;
              END CASE;
         END calculate_point ;
    /****BEGIN MAIN BLOCK********/
    BEGIN
         DBMS_OUTPUT.PUT_LINE('**********TERMS**********');
         OPEN c_GetTerms;
         LOOP
         FETCH c_GetTerms INTO v_Terms;
         DBMS_OUTPUT.PUT_LINE('Term: ' || v_Terms);
         EXIT WHEN c_GetTerms%NOTFOUND;
         END LOOP;
         CLOSE c_GetTerms;
         DBMS_OUTPUT.PUT_LINE('**********COURSES AND GRADES**********');
         OPEN c_GetCourseAndGrade;
         LOOP
         FETCH c_GetCourseAndGrade INTO v_Courses, v_Scores;
            v_Grade := convert_grade(v_Scores);
         DBMS_OUTPUT.PUT_LINE('Course: ' || v_Courses || '   Grade: ' || v_Grade);
         EXIT WHEN c_GetCourseAndGrade%NOTFOUND;
         END LOOP;
         CLOSE c_GetCourseAndGrade;
         DBMS_OUTPUT.PUT_LINE('**********GPA PER TERM**********');
         OPEN c_GPAPerTerm;
         LOOP
         FETCH c_GPAPerTerm INTO v_Terms,v_StudentID;
                      /*NEW CURSOR LOOP WILL GO HERE*/
                   v_ScoresTotal := v_ScoresTotal + v_Scores;
                      v_GPA := calculate_gpa(v_ScoresTotal, 3);
                   v_ScoresTotal :=0;
                   DBMS_OUTPUT.PUT_LINE('Term: ' || v_Terms || '   GPA: ' || v_GPA);
         EXIT WHEN c_GPAPerTerm%NOTFOUND;
         END LOOP;
         CLOSE c_GPAPerTerm;
    END get_Student_GPA;
    /

Maybe you are looking for

  • I backed up my iphone to iCloud and sold my iphone how can I get my pictures from the backup without another iphone ?

    Hi there I backed up my iPhone 4s to iCloud then sold my phone if I go on my ipad and go into iCloud-manage storage the back up is there But how do I get all the pictures from my iphone backup without another iphone ore using the ipad I need the pict

  • ODI 11g SCD@ IKM is not updating End Time and Flag

    I am implementing this IKM from Oracle ODI 11g and after executing it inserts a new row/dimension [which is correct] but sets the flag indicator for old and new ros both to '1' and Ending Timestamp value is not set for old row [I was expecting the en

  • Cursor busy state (Google Chrome problem)

    Hi OTN, On ADF page there is a form where input components has autoSubmit="true" and a value change listener. VCL perporms database operation, on start of which mouse cursor is changing its state to busy (showing busy icon). But the cursor is not cha

  • Training from the source: Dreamweaver CS3

    I'm unable to dynamically populate drop down menus as detailed in Chapter 8 p233. Testing works okay but I don't get the option to choose "rs_tournames" step 8 p 236. All I get is None but the previous steps 1-7 were completed without any problem. Fr

  • Page not loading - Events, To-do list, Notes

    Hi, I am having this error of not loading events, to-do list or notes pages. It gives me following message. "Sorry, we're having some problems bringing you this page. It's our fault not yours, so please try again later." I saw similar posts regarding