Sponsored Content
Top Forums Shell Programming and Scripting shell script to run .sql files Post 302298903 by vidyadhar85 on Wednesday 18th of March 2009 10:17:14 PM
Old 03-18-2009
Quote:
Originally Posted by balireddy_77
hi Friends,

Please help me in writing shell script to run list of sql files.
database is Oracle 9i,
unix os is solaris
Requirement is
1. sql file must take two inputs a)feed id and b)business date
2.shell script must out put .xls or .csvfile as out put without trimming any column name and column value.
result of the sql may return around 60000 records...

please provide sample .sql file ans sample unix shell script.

thanks in advance..
--bali
you can try as shown below

Code:
 
echo "enter feed id : \c"
read feed_id
echo "enter date : \c"
read buss_date
sqlplus -s / << EOF
##to stop trimming column name you can use 
column "column_name" format a(columnsize in no)
set page size 60000
spool query_result.csv
####your query here####you can use $feed_id and $buss_date in your query as you want
exit
EOF

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to run an SQL script inside a shell

How do I create a K Shell which would silently (without user input) logon to Oracle and run an SQL script? Any help will be greatly appreciated. Steve (1 Reply)
Discussion started by: stevefox
1 Replies

2. Shell Programming and Scripting

Run Sql plus in shell script

Hello, I want to connect to ssh, run a query, and store that into a variable in the shell script. Also I need to pass the variable back to php to display the query results. I have created a public/private key pair for ssh connection and that is working fine. Also I am able to run query in the... (8 Replies)
Discussion started by: shekhar2010us
8 Replies

3. Shell Programming and Scripting

How to run a SQL select query in Oracle database through shell script?

I need to run a SQL select query in Oracle database and have to capture the list of retrieved records in shell script. Also i would like to modify the query for certain condition and need to fetch it again. How can i do this? Is there a way to have a persistent connection to oracle database... (9 Replies)
Discussion started by: vel4ever
9 Replies

4. Shell Programming and Scripting

Run SQL thru shell script: how to get a new line when run sql query?

Hi, this's Pom. I'm quite a new one for shell script but I have to do sql on shell script to query some information from database. I found a concern to get a new line...When I run my script, it retrieves all data as wondering but it's shown in one line :( What should I do? I'm not sure that... (2 Replies)
Discussion started by: Kapom
2 Replies

5. Shell Programming and Scripting

Shell script to run sql query having a long listing of parameters

Hi, I have a query regarding execution of a sql query having long listing of parameters ..I need to execute this query inside a shell script. The scenario is like.... Suppose I have a file abc.txt that has the card numbers..it could be in thousands.. then I need to fire a query like ... (12 Replies)
Discussion started by: vsachan
12 Replies

6. Shell Programming and Scripting

Read files in shell script code and run a C program on those files

HI, I am trying to implement a simple shell script program that does not make use of ls or find commands as they are quite expensive on very large sets of files. So, I am trying to generate the file list myself. What I am trying to do is this: 1. Generate a file name using shell script, for... (2 Replies)
Discussion started by: shoaibjameel123
2 Replies

7. Shell Programming and Scripting

Run different SQL on multiple DBs using SHELL script

Hi Experts, I have a list of Dbs.In that DBs i need to execute some sql scripts. each sql script is unique and it should run on particular DB only. For example. i have DBs like MDC20V,NDC20V,ODC20V and sql scripts like MD.sql,ND.sql,OD.sql.so MD.sql should run only in MDC20V and ND.sql should... (1 Reply)
Discussion started by: navsan420
1 Replies

8. Shell Programming and Scripting

How can i run sql queries from UNIX shell script and retrieve data into text docs of UNIX?

Please share the doc asap as very urgently required. (1 Reply)
Discussion started by: 24ajay
1 Replies

9. Shell Programming and Scripting

run sql queries from UNIX shell script.

How can i run sql queries from UNIX shell script and retrieve data into text docs of UNIX? :confused: (1 Reply)
Discussion started by: 24ajay
1 Replies

10. Shell Programming and Scripting

Run sql query in shell script and output data save as delimited text

I want to run sql query in shell script and output data save as delimited text (delimited text would be comma) Code: SPOOL_FILE=/pgedw/dan.txt SQL=/pgedw/dan.sql sqlplus -s username/password@myhost:port/servicename <<EOF set head on set COLSEP , set linesize 32767 SET TRIMSPOOL ON SET... (8 Replies)
Discussion started by: Jaganjag
8 Replies
DB2_FETCH_ROW(3)							 1							  DB2_FETCH_ROW(3)

db2_fetch_row - Sets the result set pointer to the next row or requested row

SYNOPSIS
bool db2_fetch_row (resource $stmt, [int $row_number]) DESCRIPTION
Use db2_fetch_row(3) to iterate through a result set, or to point to a specific row in a result set if you requested a scrollable cursor. To retrieve individual fields from the result set, call the db2_result(3) function. Rather than calling db2_fetch_row(3) and db2_result(3), most applications will call one of db2_fetch_assoc(3), db2_fetch_both(3), or db2_fetch_array(3) to advance the result set pointer and return a complete row as an array. PARAMETERS
o $stmt - A valid stmt resource. o $row_number - With scrollable cursors, you can request a specific row number in the result set. Row numbering is 1-indexed. RETURN VALUES
Returns TRUE if the requested row exists in the result set. Returns FALSE if the requested row does not exist in the result set. EXAMPLES
Example #1 Iterating through a result set The following example demonstrates how to iterate through a result set with db2_fetch_row(3) and retrieve columns from the result set with db2_result(3). <?php $sql = 'SELECT name, breed FROM animals WHERE weight < ?'; $stmt = db2_prepare($conn, $sql); db2_execute($stmt, array(10)); while (db2_fetch_row($stmt)) { $name = db2_result($stmt, 0); $breed = db2_result($stmt, 1); print "$name $breed"; } ?> The above example will output: cat Pook gold fish Bubbles budgerigar Gizmo goat Rickety Ride Example #2 i5/OS recommended alternatives to db2_fetch_row/db2_result On i5/OS it is recommended that you use db2_fetch_both(3), db2_fetch_array(3), or db2_fetch_object(3) over db2_fetch_row(3)/db2_result(3). In general db2_fetch_row(3)/db2_result(3) have more issues with various column types in EBCIDIC to ASCII translation, including possible truncation in DBCS applications. You may also find the performance of db2_fetch_both(3), db2_fetch_array(3), and db2_fetch_object(3) to be superior to db2_fetch_row(3)/db2_result(3). <?php $conn = db2_connect("","",""); $sql = 'SELECT SPECIFIC_SCHEMA, SPECIFIC_NAME, ROUTINE_SCHEMA, ROUTINE_NAME, ROUTINE_TYPE, ROUTINE_CREATED, ROUTINE_BODY, IN_PARMS, OUT_PARMS, INOUT_PARMS, PARAMETER_STYLE, EXTERNAL_NAME, EXTERNAL_LANGUAGE FROM QSYS2.SYSROUTINES FETCH FIRST 2 ROWS ONLY'; $stmt = db2_exec($conn, $sql, array('cursor' => DB2_SCROLLABLE)); while ($row = db2_fetch_both($stmt)){ echo "<br>db2_fetch_both {$row['SPECIFIC_NAME']} {$row['ROUTINE_CREATED']} {$row[5]}"; } $stmt = db2_exec($conn, $sql, array('cursor' => DB2_SCROLLABLE)); while ($row = db2_fetch_array($stmt)){ echo "<br>db2_fetch_array {$row[1]} {$row[5]}"; } $stmt = db2_exec($conn, $sql, array('cursor' => DB2_SCROLLABLE)); while ($row = db2_fetch_object($stmt)){ echo "<br>db2_fetch_object {$row->SPECIFIC_NAME} {$row->ROUTINE_CREATED}"; } db2_close($conn); ?> The above example will output: db2_fetch_both MATCH_ANIMAL 2006-08-25-17.10.23.775000 2006-08-25-17.10.23.775000 db2_fetch_both MULTIRESULTS 2006-10-17-10.11.05.308000 2006-10-17-10.11.05.308000 db2_fetch_array MATCH_ANIMAL 2006-08-25-17.10.23.775000 db2_fetch_array MULTIRESULTS 2006-10-17-10.11.05.308000 db2_fetch_object MATCH_ANIMAL 2006-08-25-17.10.23.775000 db2_fetch_object MULTIRESULTS 2006-10-17-10.11.05.308000 SEE ALSO
db2_fetch_array(3), db2_fetch_assoc(3), db2_fetch_both(3), db2_fetch_object(3), db2_result(3). PHP Documentation Group DB2_FETCH_ROW(3)
All times are GMT -4. The time now is 06:22 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy