473,406 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Need sample DB2 script called by AIX script

Hi,
I am new to DB2. Does someone have a sample DB2 script they can post
here? All I want to do is execute a SQL query like this:
SELECT * FROM TABLE

Also, can someone post a sample AIX script that calls executes this
DB2 script ?

I am guessing that AIX script would looks like this:
"db2" < "C:\db2SQL.SCRIPT"
echo status: (RC=%errorlevel% )
Nov 12 '05 #1
4 9684
David wrote:
Hi,
I am new to DB2. Does someone have a sample DB2 script they can post
here? All I want to do is execute a SQL query like this:
SELECT * FROM TABLE

Also, can someone post a sample AIX script that calls executes this
DB2 script ?

I am guessing that AIX script would looks like this:
"db2" < "C:\db2SQL.SCRIPT"
echo status: (RC=%errorlevel% )


That looks very much Windows-like.

How about the following...

SQL script named "query.sql":
-------------------
SELECT *
FROM syscat.tables;
-------------------

AIX shell script (assuming ksh or bash or so):
-------------------
#!/bin/sh

db2 -t -f query.sql
if [ $? ]; then
echo "Script failed"
fi
-------------------
Or you do something like this:
-------------------
db2_out=`db2 -t -v -f query.sql`
echo $db2_out
--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #2
David wrote:
Hi,
I am new to DB2. Does someone have a sample DB2 script they can post
here? All I want to do is execute a SQL query like this:
SELECT * FROM TABLE

Also, can someone post a sample AIX script that calls executes this
DB2 script ?

I am guessing that AIX script would looks like this:
"db2" < "C:\db2SQL.SCRIPT"
echo status: (RC=%errorlevel% )


That looks very much Windows-like.

How about the following...

SQL script named "query.sql":
-------------------
SELECT *
FROM syscat.tables;
-------------------

AIX shell script (assuming ksh or bash or so):
-------------------
#!/bin/sh

db2 -t -f query.sql
if [ $? ]; then
echo "Script failed"
fi
-------------------
Or you do something like this:
-------------------
db2_out=`db2 -t -v -f query.sql`
echo $db2_out
--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #3
"Knut Stolze" <st****@de.ibm.com> wrote in message
news:c6**********@fsuj29.rz.uni-jena.de...
David wrote:
Hi,
I am new to DB2. Does someone have a sample DB2 script they can post
here? All I want to do is execute a SQL query like this:
SELECT * FROM TABLE

Also, can someone post a sample AIX script that calls executes this
DB2 script ?
[snip] How about the following... [snip] AIX shell script (assuming ksh or bash or so):
-------------------
#!/bin/sh

db2 -t -f query.sql
if [ $? ]; then
echo "Script failed"
fi
-------------------


Another option is to inline your SQL like so

#-------------------
#!/bin/sh
echo "
SELECT * FROM sometable
;" | db2 +p -vt
#-------------------

which has the benefit of allowing expansion of shell variables, e.g.:

#-------------------
#!/bin/sh
months="01 02 03 04 05 06 07 08 09 10 11 12"

for t in $months; do echo "
CREATE TABLE FACT_2004_$t
( I INT NOT NULL
, C CHAR(5)
)
;
" | db2 +p -vt ;done
#-------------------

Regards
Paul Vernon
Business Intelligence, IBM Global Services
Nov 12 '05 #4
"Knut Stolze" <st****@de.ibm.com> wrote in message
news:c6**********@fsuj29.rz.uni-jena.de...
David wrote:
Hi,
I am new to DB2. Does someone have a sample DB2 script they can post
here? All I want to do is execute a SQL query like this:
SELECT * FROM TABLE

Also, can someone post a sample AIX script that calls executes this
DB2 script ?
[snip] How about the following... [snip] AIX shell script (assuming ksh or bash or so):
-------------------
#!/bin/sh

db2 -t -f query.sql
if [ $? ]; then
echo "Script failed"
fi
-------------------


Another option is to inline your SQL like so

#-------------------
#!/bin/sh
echo "
SELECT * FROM sometable
;" | db2 +p -vt
#-------------------

which has the benefit of allowing expansion of shell variables, e.g.:

#-------------------
#!/bin/sh
months="01 02 03 04 05 06 07 08 09 10 11 12"

for t in $months; do echo "
CREATE TABLE FACT_2004_$t
( I INT NOT NULL
, C CHAR(5)
)
;
" | db2 +p -vt ;done
#-------------------

Regards
Paul Vernon
Business Intelligence, IBM Global Services
Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Brian Murphy | last post by:
<?php /* I need your help. I'd be very thankfull if write me this script.I need a script that displays a list of categories and subcategories like this: <select name="category"> <option...
5
by: deko | last post by:
In regard to running php scripts with cron - Here is a sample script: <?php //debug.php echo "<br> This is a test"; ?> I can call debug.php from a web page on my site like this:
1
by: Dan | last post by:
Hi, I am using the Employee.fdb sample that comes with Firebird 1.5.1. Everything resides on a WinXP Pro pc. I set up an ODBC connection called "FB Employee Sample" and tested it with MS Access...
3
by: John MacIntyre | last post by:
Hi, Can anybody give me a hint as to how to convert a javascript array into a vbscript array? BTW-it only needs to work in IE5 & 6 Thanks in advance, John MacIntyre VC++ / VB / ASP /...
4
by: Bob | last post by:
Below is sample code that illustrates what I'm trying to do. For sake of brevity I didn't include the properties of buildBtn that determine what data to request. The problem is I never see...
0
by: David | last post by:
Hi, I am new to DB2. Does someone have a sample DB2 script they can post here? All I want to do is execute a SQL query like this: SELECT * FROM TABLE Also, can someone post a sample AIX...
17
by: freemann | last post by:
Can anyone provide example code showing how to send form results to a results page, email and a comma delimited file? Notice that I need it going to all three locations. Details: I have forms...
7
by: fox | last post by:
Hi, Lacking javascript knowledge, I just realized why my project has a bug. I am using ASP to loop through a set of records while it creates URLs with a querystring that has a single value pair....
4
by: Jonathan Wood | last post by:
I'm trying to duplicate an HTML sample I have using my ASP.NET pages. The sample contains the following within the <headtag: <script type="text/javascript" src="flashobject.js"></script>...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.