Execution of SQLs thru loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execution of SQLs thru loop
# 1  
Old 09-27-2010
Execution of SQLs thru loop

Hi,

I have a file in which I have a number of insert statements (number is not fixed, it may have 10 statements or may be 1000....not fixed).

I want to execute these statements using a loop (1 statement per iteration).

For ex:

Input file has following statements:

Insert statement # 1;
Insert statement # 2;
Insert statement # 3;
Insert statement # 4;
Insert statement # 5;
......
......
......
......
......
Insert statement # n;

Instead of directly executing the statements, I want to execute it using a loop....1 statement per iteration. This is because I want some other stuffs after the execution of each statement.


Please post the resolution if anyone has any idea how can I do this....
# 2  
Old 09-27-2010
Code:
while read LINE
do
        echo "$LINE"
        echo "stuff to do after line;"
done < inputfile | sql_interpreter

# 3  
Old 09-27-2010
Thanks for the resolution....
can you please elaborate the steps as I am a newbe and can not make out the steps...
# 4  
Old 09-28-2010
It's a loop, which runs the READ command once per loop, reading lines one at a time into the LINE variable. It has 'inputfile' redirected into it, hence it gets its lines from there.

Inside the loop, it prints the line, then prints whatever SQL statements you'd like to insert after it. It repeats this until the file ends.
# 5  
Old 10-17-2010
Hi.

Excuse me but could you please explain what is "sql_interpreter"?
I am not so clear.

Thanks
# 6  
Old 10-17-2010
Hi.

It's not clear from this thread what database system is being used.

It would appear that "sql_interpret" is intended to mean whatever is appropriate for the database system being used. i.e. for Oracle, that would be sqlplus.
# 7  
Old 10-17-2010
Quote:
Originally Posted by orma
Excuse me but could you please explain what is "sql_interpreter"?
Whatever program you're using that interprets SQL. This isn't rocket science.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execution of loop :Splitting a single file into multiple .dat file

hdr=$(cut -c1 $path$file|head -1)#extract header”H” trl=$(cut -c|path$file|tail -1)#extract trailer “T” SplitFile=$(cut -c 50-250 $path 1$newfile |sed'$/ *$//' head -1')# to trim white space and extract table name If; then # start loop if it is a header While read I #read file Do... (4 Replies)
Discussion started by: SwagatikaP1
4 Replies

2. Shell Programming and Scripting

awk loop using array:wish to store array values from loop for use outside loop

Here's my code: awk -F '' 'NR==FNR { if (/time/ && $5>10) A=$2" "$3":"$4":"($5-01) else if (/time/ && $5<01) A=$2" "$3":"$4-01":"(59-$5) else if (/time/ && $5<=10) A=$2" "$3":"$4":0"($5-01) else if (/close/) { B=0 n1=n2; ... (2 Replies)
Discussion started by: klane
2 Replies

3. Shell Programming and Scripting

Array Variable being Assigned Values in Loop, But Gone when Loop Completes???

Hello All, Maybe I'm Missing something here but I have NOOO idea what the heck is going on with this....? I have a Variable that contains a PATTERN of what I'm considering "Illegal Characters". So what I'm doing is looping through a string containing some of these "Illegal Characters". Now... (5 Replies)
Discussion started by: mrm5102
5 Replies

4. Shell Programming and Scripting

how to pass direct SQLs to sqsh used in shell script

Hi, I simply tried this in a shell script. SQL="select getdate()" Then executed the below command: sqsh -Uxxx -Pxxxx -Sxxxx -C$SQL but i got the help options of the sqsh command. Can you please help. Thanks! (0 Replies)
Discussion started by: manojgarg
0 Replies

5. Shell Programming and Scripting

For loop like execution in shell

Hi, In the script that i work now, I wrote the script such a way that the values retrieved using a tcl script is passed into a shell script to specify the path where the specific file needs to be sourced exists. For eg: I got a path from the tcl script given below, ... (6 Replies)
Discussion started by: shivashankar_S
6 Replies

6. Shell Programming and Scripting

Problem in loop execution

Below is my code. I want a loop in this way that if folder has tag sub-folder then it will show the list of tags otherwise it will show the subfolders of that folder and then again user will select sub-folder and if tags found then show the tag list otherwise show all subfolders till he finds the... (3 Replies)
Discussion started by: anuragpgtgerman
3 Replies

7. Shell Programming and Scripting

Expect Issue Serial Forground Execution vs Concurrent Background Execution

I have an expect script that interrogates several hundred unix servers for both access and directories therein using "ssh user@host ls -l /path". The combination of host/path are unique but the host may be interrogated multiple times if there are multiple paths to test. The expect script is run... (2 Replies)
Discussion started by: twk
2 Replies

8. UNIX for Advanced & Expert Users

tar command loop during execution

I've some problem concerning tar command. Sometime tar command submitted to create a tar file, in execution loop over the same group of files. Can anyone help me? Tanks (15 Replies)
Discussion started by: Jocker
15 Replies

9. Shell Programming and Scripting

Using variables created sequentially in a loop while still inside of the loop [bash]

I'm trying to understand if it's possible to create a set of variables that are numbered based on another variable (using eval) in a loop, and then call on it before the loop ends. As an example I've written a script called question (The fist command is to show what is the contents of the... (2 Replies)
Discussion started by: DeCoTwc
2 Replies

10. Programming

how to stop execution in for loop

Hi all, I am working on a c source code nearly 2000 line . it contains one big for( i=0; i< 200 ; i++ ) loop of around 600 lines could any tell me how to break the execution of prog when the value of i is 50 in for loop so that i can check inside the loop. Thanks.. (1 Reply)
Discussion started by: useless79
1 Replies
Login or Register to Ask a Question