?
Solved

Creating a stored proc in DB2

Posted on 2011-03-15
3
Medium Priority
?
599 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 46

Accepted Solution

by:
Kent Olsen earned 2000 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

801 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