Sponsored Content
Top Forums UNIX for Beginners Questions & Answers How to use for loop to execute multiple .sql files while using SQLPLUS for db connection.? Post 303031874 by preethi87 on Thursday 7th of March 2019 03:19:30 AM
Old 03-07-2019
I tried as below constructing for loop outside SQLplus to execute all .sql files which resides in /home/*.sql files.
Throwing an error: UNEXCPETED EOF.

Code:
#!/bin/bash
cat /dev/null > output.log
date '+DATE: %m/%d/%y%nTIME:%H:%M:%S' > output.log
for file in `ls /home/*.sql`
do
echo "Executing file $file..."
sqlplus -s username/pwd << EOF >> output.log
@$file
EOF
done

Moderator's Comments:
Mod Comment Please use code tags

Last edited by Scrutinizer; 03-07-2019 at 04:23 AM.. Reason: code tags
 

10 More Discussions You Might Find Interesting

1. AIX

how can i install sqlplus and execute some sql commands

hi everybody, i am Talip, a begginner at unix based systems and i have a problem (actually, we may think myself as the problem, in this situation). i am not sure if this is the correct platform for my questions. if it is not please forgive me about this inappropriate mail. what i have: *... (2 Replies)
Discussion started by: talipk
2 Replies

2. Shell Programming and Scripting

How to execute the multiple line sql using shell script

Hi All, Please help me to write a shell script to execute the below sql query. select c.account_no,b.bill_no,a.pay_type,(b.total_due + b.recvd + b.adjusted + b.disputed + b.transferred) as amt_not_billed,d.cash_on_delivery, (select j.bill_no from billinfo_T y, bill_t j where... (1 Reply)
Discussion started by: girish.raos
1 Replies

3. UNIX for Dummies Questions & Answers

For Loop to execute a command on a series of files

Hello, I have a set of input data that I split into batches using the following command: split -l 4000000 MyInput.in Split_a Once I get the split files, I run a certain command on the split files that spews an output. So far I have been doing it without a for loop. How can I translate the... (2 Replies)
Discussion started by: Gussifinknottle
2 Replies

4. Shell Programming and Scripting

Execute multiple SQL scripts from single SQL Plus connection

Hi! I would like to do a single connection to sqlplus and execute some querys. Actually I do for every query one connection to database i.e echo 'select STATUS from v$instance; exit' > $SQL_FILE sqlplus user/pass@sid @$SQL_FILE > $SELECT_RESULT echo 'select VERSION from v$instance;... (6 Replies)
Discussion started by: guif
6 Replies

5. Shell Programming and Scripting

SQL query in a loop with single sqlplus connection

Hi, I'm trying to build a shell script that reads a set of accounts from a file. For each account I need to perform a set of sql queries. So I have a loop with a set of sqlplus connections to retrieved my data. Is it possible to have a single sqlplus connection before entering the loop and... (4 Replies)
Discussion started by: lsantacana
4 Replies

6. UNIX and Linux Applications

how to execute multiple .sql scripts from within a shell script using sqlplus

using sqlplus I want to execute a .sql script that has dbms_output statments in rhe script. I want to write the dbms_output statements from .sql file to a log file. is this possible. thanks any help would be appreciated :wall: (1 Reply)
Discussion started by: TRS80
1 Replies

7. Shell Programming and Scripting

Create Multiple UNIX Files for Multiple SQL Rows output

Dear All, I am trying to write a Unix Script which fires a sql query. The output of the sql query gives multiple rows. Each row should be saved in a separate Unix File. The number of rows of sql output can be variable. I am able save all the rows in one file but in separate files. Any... (14 Replies)
Discussion started by: Rahul_Bhasin
14 Replies

8. Shell Programming and Scripting

Need help to write a function in shell scripting to execute sql files

Hi, I am new to shell scripting and i need to write a automation script to execute sql files. I need to check the table if it is there in system tables and need to write a function to call the .sql files. For ex. I have a.sql,b.sql,c.sql files, where the sql file contains DELETE and INSERT... (1 Reply)
Discussion started by: Samah
1 Replies

9. Shell Programming and Scripting

Execute multiple files in multiple folders and also output on same folder

How to execute multiple files in multiple folders and also output to be generated in the same folder? Hello Team, I have a path like Sanity_test/*/* and it has around 100+ folders inside with files. I would like to run/execute those files and output of execution to be placed on same /... (1 Reply)
Discussion started by: pushpabuzz
1 Replies

10. Shell Programming and Scripting

How to execute 10 sql files from a folder through sqlplus in shell script?

I am new to shell scripting and i want to know how to execute the *.sql files from a folder through sqlplus in shell script and files should be execute in sequentially one by one while execution if any ORA error it has to exit from sqlplus session 1) scripts from external folder 2) logs has... (1 Reply)
Discussion started by: sreekanth Reddy
1 Replies
DBLINK_OPEN(3)						  PostgreSQL 9.2.7 Documentation					    DBLINK_OPEN(3)

NAME
dblink_open - opens a cursor in a remote database SYNOPSIS
dblink_open(text cursorname, text sql [, bool fail_on_error]) returns text dblink_open(text connname, text cursorname, text sql [, bool fail_on_error]) returns text DESCRIPTION
dblink_open() opens a cursor in a remote database. The cursor can subsequently be manipulated with dblink_fetch() and dblink_close(). ARGUMENTS
conname Name of the connection to use; omit this parameter to use the unnamed connection. cursorname The name to assign to this cursor. sql The SELECT statement that you wish to execute in the remote database, for example select * from pg_class. fail_on_error If true (the default when omitted) then an error thrown on the remote side of the connection causes an error to also be thrown locally. If false, the remote error is locally reported as a NOTICE, and the function's return value is set to ERROR. RETURN VALUE
Returns status, either OK or ERROR. NOTES
Since a cursor can only persist within a transaction, dblink_open starts an explicit transaction block (BEGIN) on the remote side, if the remote side was not already within a transaction. This transaction will be closed again when the matching dblink_close is executed. Note that if you use dblink_exec to change data between dblink_open and dblink_close, and then an error occurs or you use dblink_disconnect before dblink_close, your change will be lost because the transaction will be aborted. EXAMPLES
SELECT dblink_connect('dbname=postgres'); dblink_connect ---------------- OK (1 row) SELECT dblink_open('foo', 'select proname, prosrc from pg_proc'); dblink_open ------------- OK (1 row) PostgreSQL 9.2.7 2014-02-17 DBLINK_OPEN(3)
All times are GMT -4. The time now is 08:06 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy