Sponsored Content
Top Forums Shell Programming and Scripting Printing the output of a db2 query on to an unix file Post 302603029 by frappa on Wednesday 29th of February 2012 02:20:27 AM
Old 02-29-2012
Hi,

did you have a look at:
http://www.dbforums.com/db2/1615830-...-os-390-a.html
CSV file with Headers
Export to CSV-File - DB2 Database

see ya
fra

Last edited by frappa; 02-29-2012 at 03:29 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

flags to suppress column output, # of rows selected in db2 sql in UNIX

Hello, I am new to db2 SQL in unix so bear with me while I try to explain the situation. I have a text file that has the contents of the where condition that I am using for a db2 SQL in UNIX ksh. Here is the snippet. if ; then echo "Begin processing VALUEs" ... (1 Reply)
Discussion started by: jerardfjay
1 Replies

2. Shell Programming and Scripting

Run SQL queries in DB2 and output to file

Hi, I new to Unix and scripting. Following is my requirement. Can someone tell me whether its possible or not. Also please let me know how to proceed further if this is possible. List of queries are stored in a file. For example, I have to run a query like this: Select * from &XYZ where... (0 Replies)
Discussion started by: simhasuri
0 Replies

3. Shell Programming and Scripting

need help in reading a output of a sql query in unix script

i'm used a sql query in a unix script to get the information from table. but unable to extract the output which i need. Any help with logic will be greatly appreciated. my sql query provide output some thing like this - col1 col2 count ---- ---- ------ A B 10 c D 6 e... (8 Replies)
Discussion started by: pharos467
8 Replies

4. Shell Programming and Scripting

issue with the query output in unix

I am running a query with contains blank spaces in between in the output. But when I open and read the file in UNIX i am not able to cursor the balnk spaces instead it is moving like tabs. Please help suppose my query - Select ' '||text from tab1; the cursor should move to 1st and... (1 Reply)
Discussion started by: sbmk_design
1 Replies

5. Shell Programming and Scripting

Db2 query with script

Hi All, I want to connect two tables in DB2 using shell script and then compare the contents of two tables field by field.and i should return on the screen the un matched records .. Could any one please help me in connecting database tables using Unix and retriving data from the same. (1 Reply)
Discussion started by: kanakaraju
1 Replies

6. Shell Programming and Scripting

Need Fix in Exporting a db2 query output

When I use export for sql query in a Script : Select '1',ModHist',count(*) from cc.mdhist; it was exporting the record to a file as: "1" "ModHist" 778201 Here 1 & ModHist are coming in Doublequotes. If I run the above query directly in Unix prompt it was displaying the output as... (1 Reply)
Discussion started by: karumudi7
1 Replies

7. UNIX for Dummies Questions & Answers

UNIX Query About wc -l output

I was performing the wc -l operation in one data file the result is less when i was giving -nu on the view of the file. while giving wc -l the count is 5023 after setting line numbers in view of file is giving 5024. Can anyone help on this.... (5 Replies)
Discussion started by: abhii
5 Replies

8. AIX

DB2 user query utilization?

I am new to AIX, but not new to the UNIX world. Recently I got a request to come with some kind of report to do the following: report if user query is using > 70% CPU (within DB2) > 5 minutes. I am by no means a DB2 guru so I do not know how to get that from within it, so I was wondering if there... (4 Replies)
Discussion started by: savigabi
4 Replies

9. Shell Programming and Scripting

SQL query in UNIX script - output in flat file

Hi, I never did this before... what I want to do is execute a SQL query from a unix script and redirect sql query's output to a flat file (comma separated one) without the header info (no column names). I would also want not to print the query's output to the screen. snapshot of my script:... (13 Replies)
Discussion started by: juzz4fun
13 Replies

10. Shell Programming and Scripting

Db2 query on other host

Hello, i need some help with a script. I made a script, which connect to different hosts to get some informations. But i got now some problems with getting informations of a database (db2) which is on a other host. I tried something like var=$(rsh HOST su - db2adm -c "db2 connect to database;... (2 Replies)
Discussion started by: Cyver
2 Replies
DB2_EXECUTE(3)								 1							    DB2_EXECUTE(3)

db2_execute - Executes a prepared SQL statement

SYNOPSIS
bool db2_execute (resource $stmt, [array $parameters]) DESCRIPTION
db2_execute(3) executes an SQL statement that was prepared by db2_prepare(3). If the SQL statement returns a result set, for example, a SELECT statement or a CALL to a stored procedure that returns one or more result sets, you can retrieve a row as an array from the stmt resource using db2_fetch_assoc(3), db2_fetch_both(3), or db2_fetch_array(3). Alter- natively, you can use db2_fetch_row(3) to move the result set pointer to the next row and fetch a column at a time from that row with db2_result(3). Refer to db2_prepare(3) for a brief discussion of the advantages of using db2_prepare(3) and db2_execute(3) rather than db2_exec(3). PARAMETERS
o $stmt - A prepared statement returned from db2_prepare(3). o $parameters - An array of input parameters matching any parameter markers contained in the prepared statement. RETURN VALUES
Returns TRUE on success or FALSE on failure. EXAMPLES
Example #1 Preparing and executing an SQL statement with parameter markers The following example prepares an INSERT statement that accepts four parameter markers, then iterates over an array of arrays con- taining the input values to be passed to db2_execute(3). <?php $pet = array(0, 'cat', 'Pook', 3.2); $insert = 'INSERT INTO animals (id, breed, name, weight) VALUES (?, ?, ?, ?)'; $stmt = db2_prepare($conn, $insert); if ($stmt) { $result = db2_execute($stmt, $pet); if ($result) { print "Successfully added new pet."; } } ?> The above example will output: Successfully added new pet. Example #2 Calling a stored procedure with an OUT parameter The following example prepares a CALL statement that accepts one parameter marker representing an OUT parameter, binds the PHP variable $my_pets to the parameter using db2_bind_param(3), then issues db2_execute(3) to execute the CALL statement. After the CALL to the stored procedure has been made, the value of $num_pets changes to reflect the value returned by the stored procedure for that OUT parameter. <?php $num_pets = 0; $res = db2_prepare($conn, "CALL count_my_pets(?)"); $rc = db2_bind_param($res, 1, "num_pets", DB2_PARAM_OUT); $rc = db2_execute($res); print "I have $num_pets pets!"; ?> The above example will output: I have 7 pets! Example #3 Returning XML data as an SQL ResultSet The following example demonstrates how to work with documents stored in a XML column using the SAMPLE database. Using some pretty simple SQL/XML, this example returns some of the nodes in a XML document in an SQL ResultSet format that most users are familiar with. <?php $conn = db2_connect("SAMPLE", "db2inst1", "ibmdb2"); $query = 'SELECT * FROM XMLTABLE( XMLNAMESPACES (DEFAULT 'http://posample.org'), 'db2-fn:xmlcolumn("CUSTOMER.INFO")/customerinfo' COLUMNS "CID" VARCHAR (50) PATH '@Cid', "NAME" VARCHAR (50) PATH 'name', "PHONE" VARCHAR (50) PATH 'phone [ @type = "work"]' ) AS T WHERE NAME = ? '; $stmt = db2_prepare($conn, $query); $name = 'Kathy Smith'; if ($stmt) { db2_bind_param($stmt, 1, "name", DB2_PARAM_IN); db2_execute($stmt); while($row = db2_fetch_object($stmt)){ printf("$row->CID $row->NAME $row->PHONE "); } } db2_close($conn); ?> The above example will output: 1000 Kathy Smith 416-555-1358 1001 Kathy Smith 905-555-7258 Example #4 Performing a "JOIN" with XML data The following example works with documents stored in 2 different XML columns in the SAMPLE database. It creates 2 temporary tables from the XML documents from 2 different columns and returns an SQL ResultSet with information regarding shipping status for the cus- tomer. <?php $conn = db2_connect("SAMPLE", "db2inst1", "ibmdb2"); $query = ' SELECT A.CID, A.NAME, A.PHONE, C.PONUM, C.STATUS FROM XMLTABLE( XMLNAMESPACES (DEFAULT 'http://posample.org'), 'db2-fn:xmlcolumn("CUSTOMER.INFO")/customerinfo' COLUMNS "CID" BIGINT PATH '@Cid', "NAME" VARCHAR (50) PATH 'name', "PHONE" VARCHAR (50) PATH 'phone [ @type = "work"]' ) as A, PURCHASEORDER AS B, XMLTABLE ( XMLNAMESPACES (DEFAULT 'http://posample.org'), 'db2-fn:xmlcolumn("PURCHASEORDER.PORDER")/PurchaseOrder' COLUMNS "PONUM" BIGINT PATH '@PoNum', "STATUS" VARCHAR (50) PATH '@Status' ) as C WHERE A.CID = B.CUSTID AND B.POID = C.PONUM AND A.NAME = ? $stmt = db2_prepare($conn, $query); $name = 'Kathy Smith'; if ($stmt) { db2_bind_param($stmt, 1, "name", DB2_PARAM_IN); db2_execute($stmt); while($row = db2_fetch_object($stmt)){ printf("$row->CID $row->NAME $row->PHONE $row->PONUM $row->STATUS "); } } db2_close($conn); ?> The above example will output: 1001 Kathy Smith 905-555-7258 5002 Shipped Example #5 Returning SQL data as part of a larger XML document The following example works with a portion of the PRODUCT.DESCRIPTION documents in the SAMPLE database. It creates a XML document containing product description (XML data) and pricing info (SQL data). <?php $conn = db2_connect("SAMPLE", "db2inst1", "ibmdb2"); $query = ' SELECT XMLSERIALIZE( XMLQUERY(' declare boundary-space strip; declare default element namespace "http://posample.org"; <promoList> { for $prod in $doc/product where $prod/description/price < 10.00 order by $prod/description/price ascending return( <promoitem> { $prod, <startdate> {$start} </startdate>, <enddate> {$end} </enddate>, <promoprice> {$promo} </promoprice> } </promoitem> ) } </promoList> ' passing by ref DESCRIPTION AS "doc", PROMOSTART as "start", PROMOEND as "end", PROMOPRICE as "promo" RETURNING SEQUENCE) AS CLOB (32000)) AS NEW_PRODUCT_INFO FROM PRODUCT WHERE PID = ? $stmt = db2_prepare($conn, $query); $pid = "100-100-01"; if ($stmt) { db2_bind_param($stmt, 1, "pid", DB2_PARAM_IN); db2_execute($stmt); while($row = db2_fetch_array($stmt)){ printf("$row[0] "); } } db2_close($conn); ?> The above example will output: <promoList xmlns="http://posample.org"> <promoitem> <product pid="100-100-01"> <description> <name>Snow Shovel, Basic 22 inch</name> <details>Basic Snow Shovel, 22 inches wide, straight handle with D-Grip</details> <price>9.99</price> <weight>1 kg</weight> </description> </product> <startdate>2004-11-19</startdate> <enddate>2004-12-19</enddate> <promoprice>7.25</promoprice> </promoitem> </promoList> SEE ALSO
db2_exec(3), db2_fetch_array(3), db2_fetch_assoc(3), db2_fetch_both(3), db2_fetch_row(3), db2_prepare(3), db2_result(3). PHP Documentation Group DB2_EXECUTE(3)
All times are GMT -4. The time now is 10:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy