To call a Oracle sql file 1000 times


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To call a Oracle sql file 1000 times
# 1  
Old 11-25-2010
To call a Oracle sql file 1000 times

Hi Guys,

Even though, i have called db2 sql file earlier, this is my first time to call a oracle sql file.

I need to make a database(oracle) connection and then call the sql file in a loop.

Can you please help me out.

Thanks for your help and time.

Regards,
Magesh
# 2  
Old 11-25-2010
Code:
#!/bin/ksh
cnt=0
while :
do
sqlplus -s username/password@dbname << EOF
  spool ${cnt}.txt
  @/path/to/sql/file/filename
EOF
cnt=$(( $cnt + 1 ))
if [ $cnt -gt 1000 ] ; then
  break
fi
done

This just uses the variable cnt inside the sql to create a spool file 0.txt ... 1000.txt
You do not have to use a shell variable inside the here document.

NOTE: see the last EOF (used to delimit the here doc)? It has to be in column 1 (left hand side) in the script.
# 3  
Old 11-25-2010
Some general considerations...

You should do such kind of tasks in SQL SQL+ or PL/SQL.

Doing this under unix is a very bad design and not performance friendly (as well as I/O consumming (mupltiplied by 1000) ).

You should review the overall process design : what are the contents of these files ? what are they supposed to do ?

Can this be done in 1 file within an SQL loop that will be loaded and processed by the DB memory ? ... instead of causing physical read x 1000 at unix level .

You should always take in consideration the performances (I/O, memory & CPU consumption) and make sure the way you've chosen to perform the needed task is an accurate and efficient one.
# 4  
Old 11-25-2010
Plus, sql*plus is not good at moving data like isql, I guess too much designed by Informix and MAINFRAME envy for fiddly formatting. You might use jisql and JDBC, or UNIXodbc isql.

Running 1000 times says it should be calling a stored procedure or PL/SQL loop, where you send the parameters in and the SQL runs with them inside.

As I recall, ORACLE net login is like many others: a host, a port, an instance name, an id and a password. It can also run locally in UNIX on a pipe. Once in, your id is not local to tables unless someone made synonyms or views, as it is much more id = schema-catalog-name than some others where your id is, by request or just by default, associated with a schema-catalog-name.

Last edited by DGPickett; 11-25-2010 at 02:39 PM..
# 5  
Old 11-25-2010
Hi DGPickett Smilie

Ok that was general consideration and i agree :
Quote:
Running 1000 times says it should be calling a stored procedure or PL/SQL loop, where you send the parameters in and the SQL runs with them inside.
That was the way i was thinking of ... (Of course it still may depends on what these files
actually contains and what is the final goal to achieve.)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to call sql file

hi , the below script contains sql query and after executed it sends the output of the query (output.txt) to an email body with conditional subject line based on the output of all_counts_match.txt. i want to make this script generic so that it can accept the sql file as parameter and can... (5 Replies)
Discussion started by: itzkashi
5 Replies

2. Shell Programming and Scripting

To call Oracle procedure by reading parameter file in UNIX

hi Guys, is there a way to pass parameter into oracle store procedure by reading date range in file and increment accordingly. Something like this file.txt 01-JAN-2015 03-JAN-2015 sqlplus -s user/pwd@DB execute TEST( to_date( '01-JAN-2015, 'dd.mm.yyyy' ), to_date( '03-JAN-2015', ... (1 Reply)
Discussion started by: rohit_shinez
1 Replies

3. Shell Programming and Scripting

Need Help: Shell script to call sql session with variables stored in .txt file

Hi, I need help in writing a shell script which can read data from a text file (Cancel_ID.txt) and then calls sqlplus session (Cancel.sql) with the first line parameter of the text file ("0322600453") till all rows are not completed. ... (4 Replies)
Discussion started by: Khan28
4 Replies

4. Shell Programming and Scripting

How to call Oracle package in shell file?

How to call oracle package in shell file in my shell file, I have Export SQL FILE =$Home_dir select.sql if I want to add call two function in package how can I do it :( (2 Replies)
Discussion started by: Hscript
2 Replies

5. Solaris

Primary key issue when running Oracle sql file

I got a issue with running the following script below if I remove the inserts and alter table the tables will install just fine but if I try and do the full thing in one go i get the below error dose any one have any ideas on this problem? its got me spinning, thanks. REM REM List of... (1 Reply)
Discussion started by: Wpgn
1 Replies

6. Shell Programming and Scripting

Need to write shell script for my .sql file call

Hi Guys, I need to write a simple shell script which will generate a .csv file/report by calling .sql file inside a shell script. Can somebody help me on this. Thanks in advance! Regards, LK (7 Replies)
Discussion started by: lakshmanraok117
7 Replies

7. Shell Programming and Scripting

Capture rows for a column in file from delete sql -Oracle

Hi, This may not be the right forum but i am hoping someone knows an answer to this. I have to capture rows for a column that was deleted. How can i do that without having to write a select query? delete from myschema.mytable where currentdatetimestamp > columnDate this should delete 5... (4 Replies)
Discussion started by: jakSun8
4 Replies

8. UNIX for Advanced & Expert Users

Call parallel sql scripts from shell and return status when both sql are done

Hi Experts: I have a shell script that's kicked off by cron. Inside this shell script, I need to kick off two or more oracle sql scripts to process different groups of tables. And when both sql scripts are done, I will continue in the shell script to do other things like checking processing... (3 Replies)
Discussion started by: huasheng8
3 Replies

9. Shell Programming and Scripting

call a passwd file to a script multiple times

Hello everybody, I have a requirement in my script.. When i'am executing a script, it'll ask a passwd of some service account.. I need to pass it to the script through a zipped file when it asks for it. The script can be executed by more people many number times. So for securty purpose, it... (1 Reply)
Discussion started by: raghu.iv85
1 Replies

10. Shell Programming and Scripting

Unix call to Oracle PL/SQL pkg/store.proc

HI, I'm trying to get this right, please can you help. In my unix korn shell script, I call an oracle stored proc within a package and I specify 3 parameters, 2 of which are IN OUT parameters (i.e. I expect the stored proc to change them and return them back to me). Does the unix code... (7 Replies)
Discussion started by: csong2
7 Replies
Login or Register to Ask a Question