Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

how to create Store procedures without using development c..

 
   Database Forums (Home) -> DB2 RSS
Next:  Is there is a way in DB2 to return multiple field..  
Author Message
mmikram

External


Since: Jun 04, 2008
Posts: 1



(Msg. 1) Posted: Wed Jun 04, 2008 10:56 pm
Post subject: how to create Store procedures without using development center
Archived from groups: comp>databases>ibm-db2 (more info?)

Hi,
I am new to DB2, My installation of DB does not include Development
center...
but i need to create stored procedures.
Geeks please help me how to create stored procedure and please step by
step..

 >> Stay informed about: how to create Store procedures without using development c.. 
Back to top
Login to vote
Dave Hughes

External


Since: Mar 07, 2006
Posts: 69



(Msg. 2) Posted: Thu Jun 05, 2008 1:46 am
Post subject: Re: how to create Store procedures without using development center [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

wrote:

> Hi,
> I am new to DB2, My installation of DB does not include Development
> center...
> but i need to create stored procedures.
> Geeks please help me how to create stored procedure and please step by
> step..

As Jean-Marc points out, you can grab Data Studio and use that.
Alternatively, if you prefer a more light-weight solution (Data Studio,
being Eclipse based, is *fat*), albeit without much fancy debugging
functionality, you can simply stick the code for your procedure in a
text file and run it with the CLP.

So, step by step (assuming you're on Windows):

1. Stick the code (nicked from an example in the InfoCenter Smile for the
stored procedure in a text file, e.g. notepad createproc.sql:

DROP SPECIFIC PROCEDURE MEDIAN_SET@

CREATE PROCEDURE MEDIAN_RESULT_SET (OUT medianSalary DOUBLE)
SPECIFIC MEDIAN_SET
RESULT SETS 1
LANGUAGE SQL
BEGIN
DECLARE v_numRecords INT DEFAULT 1;
DECLARE v_counter INT DEFAULT 0;
DECLARE c1 CURSOR FOR
SELECT CAST(salary AS DOUBLE)
FROM staff
ORDER BY salary;
DECLARE c2 CURSOR WITH RETURN FOR
SELECT name, job, CAST(salary AS INTEGER)
FROM staff
WHERE salary > medianSalary
ORDER BY salary;
DECLARE EXIT HANDLER FOR NOT FOUND
SET medianSalary = 6666;
SET medianSalary = 0;
SELECT COUNT(*) INTO v_numRecords
FROM STAFF;
OPEN c1;
WHILE v_counter < (v_numRecords / 2 + 1) DO
FETCH c1 INTO medianSalary;
SET v_counter = v_counter + 1;
END WHILE;
CLOSE c1;
OPEN c2;
END@

Note the use of an statement terminator at the end (@ in this case).
You can't use semi-colon as it's being used within the stored proc
definition and would terminate the definition early.

2. Fire up a DB2 Command Window (should be under the Start menu, IBM
DB2, Command Line Tools)

3. Enter the following to open a connection to the database in which
you wish to create the stored proc (note: the database must be
cataloged - use the Configuration Assistant for this):

db2 CONNECT TO targetdb USER username USING password

4. Run the script you created above with the following command line
(note that we need to tell DB2 about the alternate statement
terminator, (-td@) - the other switches just tell DB2 to echo commands
as they are executed (-v), and what file to run (-f)):

db2 -td@ -v -f createproc.sql


Cheers,

Dave.

 >> Stay informed about: how to create Store procedures without using development c.. 
Back to top
Login to vote
Jean-Marc Blaise

External


Since: Feb 12, 2008
Posts: 13



(Msg. 3) Posted: Thu Jun 05, 2008 8:07 am
Post subject: Re: how to create Store procedures without using development center [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hi,

You can download for free IBM Data Studio www.ibm.com/software/data/studio.
It's an environment based on eclipse that will allow you to create SQL or
Java procedures, and debug them .... and MUCH MORE.
This tool works on DB2 8.x, 9.1 and 9.5 databases.

HTH,

Jean-Marc

wrote in message

> Hi,
> I am new to DB2, My installation of DB does not include Development
> center...
> but i need to create stored procedures.
> Geeks please help me how to create stored procedure and please step by
> step..
 >> Stay informed about: how to create Store procedures without using development c.. 
Back to top
Login to vote
Display posts from previous:   
   Database Forums (Home) -> DB2 All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]