Advertisement

05.25.2007 at 08:14AM PDT, ID: 22594980
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.6

sample db2 sql pl (ver 8.2.7) having cursors..

Asked by mahjag in DB2 Database

Tags: , ,

I have a sample db2 stored procdure written that has cursors, I needed experts to review and give me hints..

Requirement is to write a SQL PL SP that has cursor to iterate a table and then call another SP with some parameters, also to log the exceptions clearly as the data rejected is sensitive and needs to reviewed by users for re-processing.

Here is my attempt..

create procedure TEST()
LANGUAGE SQL
BEGIN
 Declare v_counter             INTEGER;
 DECLARE v_message             varchar(70);

 DECLARE v_sqlstate            varchar(5);

 DECLARE v_at_delete           smallint;
   DECLARE v_start_timestamp     timestamp;
   DECLARE v_end_timestamp       timestamp;
   DECLARE v_procstart_timestamp     timestamp;
   DECLARE v_procend_timestamp       timestamp;



 declare SQLSTATE char(5);
 DECLARE at_notfound SMALLINT DEFAULT 0;
 DECLARE at_null SMALLINT DEFAULT 0;
 declare not_found
  CONDITION for SQLSTATE '02000';
 declare  SQLEXEPTION
 CONDITION for SQLSTATE '23502';


  DECLARE MyCursor Cursor with hold  for
    SELECT col1,col2...
              from tableA
        ORDER BY col1
    FOR READ ONLY;



 DECLARE CONTINUE HANDLER FOR not_found
    BEGIN
   SET at_notfound = 1;
   END;
    DECLARE CONTINUE HANDLER FOR SQLEXEPTION
    BEGIN
   SET at_null = 1;
    END;
   set v_procstart_timestamp = current timestamp;
   SET v_counter = 0;



   set v_start_timestamp = current timestamp;
   OPEN MyCursor;
   LOOP
   FETCH MyCursor INTO
         v_col1,v_col2...   ;      
            SET  v_counter =v_counter+1;

        CALL Another_SP(v_col1,v_col2...);                              );


  END LOOP;
     CLOSE  MyCursor;
     set v_end_timestamp = current timestamp;
INSERT INTO ERRORS VALUES('TST',current timestamp,
                                 null,char(v_start_timestamp)||' '||char(v_end_timestamp));


set v_procend_timestamp = current timestamp;
INSERT INTO ERRORS VALUES('TST',current timestamp,
                                 null,char(v_procstart_timestamp)||' '||char(v_procend_timestamp));
commit;
END


1. Few points - when I declared cursor not having"with hold" option it gave SQL0501N error so I had to use "Wtih hold" -
I am not sure why I need that explanations on this will be helpful

2. When I ran 2-3 times I got A database manager error occurred.[IBM][CLI Driver][DB2/LINUXX8664] SQL0289N  Unable to allocate new pages in table space "Tab_space1".  SQLSTATE=57011

Not sure this is becuase of my stored procedure, but wanted to find out before I deploy this in production..

Thanks a lot!!Start Free Trial
[+][-]05.25.2007 at 01:23PM PDT, ID: 19159741

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.25.2007 at 01:28PM PDT, ID: 19159770

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.25.2007 at 01:29PM PDT, ID: 19159779

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.25.2007 at 01:31PM PDT, ID: 19159786

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.26.2007 at 10:41PM PDT, ID: 19163615

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: DB2 Database
Tags: db2, sql, cursor
Sign Up Now!
Solution Provided By: momi_sabag
Participating Experts: 2
Solution Grade: B
 
 
[+][-]05.29.2007 at 01:04PM PDT, ID: 19175101

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.04.2007 at 08:10AM PDT, ID: 19209145

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.04.2007 at 08:18AM PDT, ID: 19209215

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32