[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[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!

9.2

Dynamic sql in a cursor

Asked by williampeck in Oracle CRM, PL / SQL

Tags: Oracle, PL*Sql

I have very similar sql and code and want to consolidate.

but to do so I need a dynamic cursor where the table is set based on a value.

If this can be done, it would cut the code by about 1/2, a reasonable goal.

But if there is too much hoop-jumping for a little bit of savings, it's not worth it. The current code base is table and basically never changes. I am making a change to make the code more efficient, but once done, this will also be rarely changed code.

In the cursors below, the only difference is the table name

In the code below, the only difference is the cursor name reference.


1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
-- cursors
   -- PClm Clm   
   cursor pclm_clm_cur is
   SELECT ods_stus_cd as stus_cd, count(*) as count_for_status, sum(clm_tot_paid_amt) as curs_paid_amt,
          case ods_stus_cd when 'L' then 1 when 'D' then 2 when 'I' then 3 when 'E' then 4 
          end as stus_cd_array_num
    FROM ods.pclm_clm
    WHERE clm_seqno BETWEEN min_seqno AND max_seqno
    AND ods_stus_cd IS NOT NULL
    AND activity_timestamp >= lookback_date
    group by ods_stus_cd
    order by case ods_stus_cd when 'L' then 1 when 'D' then 2 when 'I' then 3 when 'E' then 4 end;
    pclm_clm_rec pclm_clm_cur%rowtype;
 
-- Clm Clm
   cursor clm_clm_cur is
   SELECT ods_stus_cd as stus_cd, count(*) as count_for_status, sum(clm_tot_paid_amt) as curs_paid_amt,
          case ods_stus_cd when 'L' then 1 when 'D' then 2 when 'I' then 3 when 'E' then 4 end as stus_cd_array_num
   FROM ods.clm_clm
    WHERE clm_seqno BETWEEN min_seqno AND max_seqno
    AND ods_stus_cd IS NOT NULL
    AND activity_timestamp >= lookback_date
    group by ods_stus_cd
    order by case ods_stus_cd when 'L' then 1 when 'D' then 2 when 'I' then 3 when 'E' then 4 end;
    clm_clm_rec clm_clm_cur%rowtype;
 
   -- code
   IF srce_sys_cd IN ('038','107','106','109','140','168','177') THEN
 
      for pclm_clm_rec in pclm_clm_cur
      loop
         UTL_FILE.PUT_LINE(out_file,'    Status Code = ' || pclm_clm_rec.stus_cd || '      ' || to_char(pclm_clm_rec.count_for_status,'99,999,990') || '  SRCE_CLM_PAID_AMT = ' || to_char(pclm_clm_rec.curs_paid_amt,'9,999,999,990.00'));
         utl_file.put_line(out_file, '                                      ');
            
         stus_cd_tot(pclm_clm_rec.stus_cd_array_num) := stus_cd_tot(pclm_clm_rec.stus_cd_array_num) + pclm_clm_rec.curs_paid_amt;
          
         if stus_cnt > 0 then               
            if pclm_clm_rec.stus_cd in ('L','D','E') then
               errors_encountered_flg := true;
            end if;
         end if;
       end loop;
   ELSE
       for clm_clm_rec in clm_clm_cur
       loop
         UTL_FILE.PUT_LINE(out_file,'    Status Code = ' || clm_clm_rec.stus_cd || '      ' || to_char(clm_clm_rec.count_for_status,'99,999,990') || '  SRCE_CLM_PAID_AMT = ' || to_char(clm_clm_rec.curs_paid_amt,'9,999,999,990.00'));
         utl_file.put_line(out_file, '                                      ');
            
         stus_cd_tot(clm_clm_rec.stus_cd_array_num) := stus_cd_tot(clm_clm_rec.stus_cd_array_num) + clm_clm_rec.curs_paid_amt;
         if stus_cnt > 0 then
            if clm_clm_rec.stus_cd in ('L','D','E') then
               errors_encountered_flg := true;
            end if;           
         end if;
       end loop;
   END IF;
   UTL_FILE.FFLUSH(out_file);
[+][-]05/12/09 02:00 PM, ID: 24369377Accepted Solution

View this solution now by starting your 30-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

Zones: Oracle CRM, PL / SQL
Tags: Oracle, PL*Sql
Sign Up Now!
Solution Provided By: sdstuber
Participating Experts: 1
Solution Grade: A
 
[+][-]05/28/09 12:50 PM, ID: 24497205Author Comment

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 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/28/09 01:41 PM, ID: 24497648Expert Comment

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 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89 - Hierarchy / EE_QW_3_20080625