Solved

Creating a stored proc in DB2

Posted on 2011-03-15
3
592 Views
Last Modified: 2012-05-11

How can I write a DB2 stored procedure with 1 input parameter? If so, how can I call it. I am new to DB2 and need your help.

The input parameter is dt and datatype is date
I have a bunch of SQL queries like this --

DECLARE GLOBAL TEMPORARY TABLE Session.DATE
   (EFFECTIVE_DTE DATE NOT NULL)
     ON COMMIT PRESERVE ROWS WITH REPLACE;
   
      Insert  into Session.DATE
    VALUES (dt);
select * from Session.DATE;
select * from session.DATE d1, id t1
where t1.joining_dt = d1.DATE;

I want to put all these statements into a stored procedure. How can I do it?
0
Comment
Question by:sunny82
3 Comments
 
LVL 45

Accepted Solution

by:
Kdo earned 500 total points
ID: 35141437
Hi Sunny,

Is this classwork?  I'll be glad to help, but the kinds of help that we can give is different for classwork than other kinds of assistance.

The general rule is that you can create a stored procedure to do just about anything.  For the most part, put the declaration before and around your code.


CREATE PROCEDURE myprocedure
AS
BEGIN
  -- your code here
END;

One item that will cause you stress, until you realize why, is the SELECT statement.  They won't work in a stored procedure as you have them written.  The SELECT must do something with the results and your SQL doesn't direct the results.  You must SELECT INTO a variable or use the results of the SELECT to do something like INSERT or UPDATE another table.



Good Luck,
Kent
0
 
LVL 37

Expert Comment

by:momi_sabag
ID: 35141444
you can find examples here
http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/topic/com.ibm.db2.luw.sql.ref.doc/doc/r0008329.html

calling a stored procedure is done with the call statement
0
 

Author Comment

by:sunny82
ID: 35141660
cool, thanks
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recursive SQL in UDB/LUW (you can use 'recursive' and 'SQL' in the same sentence) A growing number of database queries lend themselves to recursive solutions.  It's not always easy to spot when recursion is called for, especially for people una…
Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now