Home » SQL & PL/SQL » SQL & PL/SQL » problem with loading the ids into table
problem with loading the ids into table [message #217243] Thu, 01 February 2007 05:32
seenujanu
Messages: 53
Registered: August 2006
Location: chennai
Member
Hi Friends,

i had a problem with loading the ids into table

i had 4 tables
1st Table
id is Primarykey

id entryname
1         john
2         ranu
3         seenu

2nd table 

id and id1 are Primarykeys

id  id1   entryname1
1           1          cpu
1           2          monitor
1           3          wer
2           4          hjk
2           5          wr
3           6          opop

3rd table

id and id2  are Primarykeys

id    id2   entryname2
1           2          monitor
1           3          wer
2           4          hjk
2           5          wr
3           6          opop

4th table

id and id2  and id3 are Primarykeys


id      id2   id3   entryname3
1         1    1          cpu
1         1    2          monitor
1         1    3          wer
2         2    4          hjk
2         2    5          wr


i want to load the aboce tabels of ids into 5th table
5th table

id   id1    id2   id3  
1     1      1     1    
             2     2 
             3     3    
1     2      2     4    
1     3      3     5    
2     4      4     6    
2     5      5         


P_ID ,P_ID1 ,P_ID2 ,P_ID3 ARE WIHT NULL PARAMETERS
  OPEN c_t1(p_id);
  FETCH c_t1 INTO r_t1;
  IF c_t1%FOUND THEN
    CLOSE c_t1;
    FOR c_t1 IN c_t1(r_1sttable.id)
      LOOP
        OPEN c_2ndtable(r_1sttable.id);
        FETCH c_2ndtable INTO r_2ndtable;
        IF c_2ndtable%FOUND THEN
          CLOSE c_2ndtable;
          FOR r_2ndtable IN c_2ndtable(r_1sttable.id)
            LOOP
              OPEN c_3rdtable(r_2ndtable.id);
              FETCH c_3rdtable INTO r_3rdtable;
              IF c_3rdtable%FOUND THEN
                CLOSE c_3rdtable;
                FOR r_3rdtable IN c_3rdtable(r_2ndtable.id)
                  LOOP
                    OPEN c_4rdtable(r_3ndtable.id);
                    FETCH c_4rdtable INTO r_4rdtable;
                    IF c_4rdtable%FOUND THEN
                      CLOSE c_4rdtable;
                      FOR r_4rdtable IN c_4rdtable(r_3Rdtable.id)
                        LOOP
                          BEGIN
                          INSERT INTO 5th table
                                 (id
                                 ,id1 
                                 ,id2 
                                 ,id3 
                                 )
                          VALUES
                                 (r_4rdtable.id
                                 ,r_3rdtable.id1
                                 ,r_4rdtable.id2
                                 ,r_4rdtable.id3
                                  );
                          COMMIT;
                          END;
                        END LOOP;
                    ELSE
                      BEGIN
                        INSERT INTO 5th table
                               (id
                               ,id1 
                               ,id2 
                               ,id3 
                               )
                        VALUES
                               (r_3rdtable.id
                               ,r_2rdtable.id1
                               ,r_3rdtable.id2
                               ,p_id3
                                );
                        COMMIT;
                      END;
                  END LOOP;
              ELSE
                BEGIN
                  INSERT INTO 5th table
                             (id    
                             ,id1   
                             ,id2   
                             ,id3   
                             )      
                  VALUES
                             (r_2ndtable.id
                             ,r_2ndtable.id1      
                             ,p_id2       
                             ,p_id3      
                              );
                  CLOSE c_3rdtable;
                  COMMIT;
                END;
              END IF;
            END LOOP;
        ELSE
          BEGIN
            INSERT INTO 5th table
                        (id   
                        ,id1  
                        ,id2  
                        ,id3  
                        )
            VALUES
                         (r_1sttable.id
                         ,p_id1       
                         ,p_id2       
                         ,p_id3       
                          );
            COMMIT;
          END;
          CLOSE c_2ndtable;
        END IF;
  ELSE
    CLOSE c_1sttable;
  END IF;

if the data is having in 1sttable it is not loading

if the data is having in 1sttable and 2nd table it is loading in the 5th table

would u plz resolve this problem or any other way to load the data or any Query



Regards
seenu

[EDIT] Please, next time add [code] tags by yourself to improve readability. Without them, the code is a mess.

[Updated on: Thu, 01 February 2007 05:43] by Moderator

Report message to a moderator

Previous Topic: Query
Next Topic: Searching Text Query - Using SQL
Goto Forum:
  


Current Time: Sat Dec 10 16:24:09 CST 2016

Total time taken to generate the page: 0.14089 seconds