Advertisement

10.03.2007 at 03:38AM PDT, ID: 22868746
[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.0

nested cursor to insert data into another table

Asked by countrymeister in Oracle 10.x, Oracle Database

Tags: , , , ,

I am using oracle 10g, I have  a parent table Table 1, child table table 2 and a third table Table 3, where I want to insert the data into from Table 1
There is also data from the child table that needs to be populated in Table 3.
In short Table 3 has a flat structure of therealtional data in Table1 and Table 2

Hereis what I have so far. I open a cursor for the parent and then loop through the parent cursor.
I would like to open the child cursor and fetch upto 4 rows, and then based on the child cursor row count,populate the variables v_empid_1, v_credit1, and then use the values to insert into Table3
Not sure if I have the right syntax


CREATE OR REPLACE PROCEDURE db_LOAD(

P_FROMDATE        IN varchar
,P_TODATE         IN varchar  
,P_LEGAL          IN varchar
,P_ASSET          IN varchar
,P_CURRENCY       IN varchar
,P_PROCESSED_BY   IN varchar
,P_ROWS_INSERTED  OUT NUMBER )

 

AS

v_empid_1 varchar;
v_empid_2 varchar;
v_empid_3 varchar;
v_empid_4 varchar;
v_credit_1 number;
v_credit_2 number;
v_credit_3 number;
v_credit_4 number;

CURSOR
LOAD_DATA is
select
  rowid                   ,
  ID                         ,
 CREATED_BY       ,
 CODE        

            FROM
         TABLE1
        WHERE
            PROCESS_FLAG = 'N';

  BEGIN    

  dbms_output.put_line('From Date - '|| P_FROMDATE );
  dbms_output.put_line('To Date -  ' || P_TODATE);
  dbms_output.put_line('Legal Entity - ' || P_LEGAL);
  dbms_output.put_line('Asset Class - ' || P_ASSET);
  dbms_output.put_line('Currency - ' || P_CURRENCY);
  dbms_output.put_line('Processed By - ' || P_PROCESSED_BY);

 FOR LOAD_REC in LOAD_DATA
v_empid_1:= '';
v_empid_2:=  '';
v_empid_3:=  '';
v_empid_4:=  '';
v_credit_1:= 0;
v_credit_2:= 0;
v_credit_3:= 0;
v_credit_4:= 0;

LOOP
   CURSOR
        LOAD_CHILD IS
      select *
            from (select *
                       from TABLE2  
                       order by EMP_ID desc)
            where rownum < 5;
     FOR CHILD_REC IN LOAD_CHILD
     //NEED TO ADD CODE SO THAT WHEN THE CURSOR ROW IS N
    //POPULATE
   IF LOAD_CHILD.ROWCOUNt =1
         V_EMPID_1 = child_rec.emp_id;
         v_credir_1 = chil_rec.credit;
  elseif LOAD_CHILD.rowcount = 2
      V_EMPID_2 = child_rec.emp_id;
         v_credir_2 = chil_rec.credit;

 

 INSERT INTO TABLE3
 (
  LINE_SEQ          ,
  CREATED_BY        ,
  CODE ,
  EMPYID1           ,
  EMPYID2           ,
  EMPYID3           ,
  EMPYID4           ,
  CREDIT_AMT1       ,
  CREDIT_AMT2       ,
  CREDIT_AMT3       ,
  CREDIT_AMT4    
  )
VALUES
(         db.LINENUMBERSEQUENCE.NEXTVAL,
          LOAD_REC.CREATED_BY ,
          LOAD_REC.CODE ,
          v_empid_1,
          v_empid_2,
          v_empid_3,
          v_empid_4,
         v_credit_1,
         v_credit_2,
         v_credit_3,
         v_credit_4        
          );

 

 UPDATE TABLE1

  SET PROCESS_FLAG = 'Y'
  where rowid = LOAD_REC.ROWID;

 

 

Start Free Trial
 
Loading Advertisement...
 
[+][-]10.03.2007 at 03:55AM PDT, ID: 20005293

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

 
[+][-]10.03.2007 at 05:20AM PDT, ID: 20005720

View this solution now by starting your 14-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 10.x, Oracle Database
Tags: table, insert, oracle, cursor, another
Sign Up Now!
Solution Provided By: GGuzdziol
Participating Experts: 2
Solution Grade: A
 
 
[+][-]10.03.2007 at 07:39AM PDT, ID: 20006897

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

 
[+][-]10.03.2007 at 07:44AM PDT, ID: 20006932

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 14-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]10.03.2007 at 08:14AM PDT, ID: 20007267

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

 
[+][-]10.03.2007 at 08:52AM PDT, ID: 20007635

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

 
[+][-]10.04.2007 at 08:24AM PDT, ID: 20014933

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

 
 
Loading Advertisement...
20081112-EE-VQP-43 - Hierarchy / EE_QW_2_20070628