Find the answer to your Linux question:
Results 1 to 2 of 2
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 ...
  1. #1
    Just Joined!
    Join Date
    Oct 2009
    Posts
    2

    Looping through a shell script with sql statements

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

    Code:
    for i in *
    do
      cp $i /home/temp
    2 . Create a snapshot(n) table : Initialize n = 1

    Code:
    create table test insert account_no, balance from records_all;
    -- creates my snapshot table and inserts records in SQL

    3. Checking if the table has been created successfully:

    Code:
    select count(*) from snapshot1
    -- query out the number of records in the table -- always fixed, say at 400000


    Code:
    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,

    Code:
    echo " select max(value) from results_all "
    -- printing the max value to console

    5. Process my files using the following jobs:

    Code:
    ./runscript.ksh - READ -i $m
    ( m - initial value 001 )
    Code:
    ./runscript.ksh - WRITE -i $m
    ( m - initial value 001 -- same as READ process_id )

    -- increment m by 1

    6. Wait for success log

    Code:
    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.

    Code:
    done
    -- End of Step 1

    Pointers on getting me moving will be very valuable.

    thanks,

    Kristina

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    First of all, you can do this (the SQL commands) in an SQL script (sqlplus), not a system shell script (bash, csh, ksh, etc). I would suggest that you first review the documentation for sqlplus.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...