16.10.2015 Views

Getting Started with IBM Data Studio for DB2

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 8 – Developing SQL stored procedures 261<br />

12. View the results: The Debug perspective provides the same SQL Results view as in<br />

the <strong>IBM</strong> SQL and Routine Development perspective so that you can see the status<br />

and results of running the stored procedure. The Parameters tab on the right in the<br />

SQL Results view will show your stored procedure’s input and output parameters. This<br />

is shown in Figure 8.30. The value of p_in is 1, since that is the value that caused<br />

the stored procedure to run (even though you changed it to 2 while in the debug mode<br />

be<strong>for</strong>e executing the IF condition). The value ofp_out is 3.<br />

Figure 8.30 – View the debug results<br />

8.4 Exercises<br />

Now that you have gone through the process of creating, deploying, testing, debugging and<br />

running a stored procedure, it is time <strong>for</strong> you to test this yourself by creating the following<br />

procedure. Note the procedure has one intentional bug <strong>for</strong> you to discover. The output of<br />

the procedure should be 2, 3 or 4.<br />

CREATE PROCEDURE SP1 (IN p_in INT, OUT p_out INT)<br />

P1: BEGIN<br />

END P1<br />

IF p_in = 1 THEN<br />

SET p_in = 2;<br />

ELSEIF p_in = 2 THEN<br />

ELSE<br />

END IF;<br />

8.5 Summary<br />

SET p_out = 3;<br />

SET p_out 4;<br />

In this chapter, you learned the value of using stored procedures to improve per<strong>for</strong>mance<br />

of SQL access by being able to process a set of SQL on the database server rather than<br />

sending each request over the wire separately. In addition, by encapsulating the database<br />

logic, those stored procedures can be called and used by multiple applications.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!