finding Difference in pl/sql

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cheguashwini
    New Member
    • Jan 2008
    • 1

    finding Difference in pl/sql

    Hi
    I have a problem.
    I have two tables...table1 and table2.
    table1 has the column latitude and sno(serial number) and table2 has the column lat and sno(serial number) .
    i have to find the difference of all the values in column latitude from table 1 with all the values in column lat from table 2 and place it in a new table result having column difference

    i have written this code but i am getting error as missing elements. Can anyone please guide me?
    [code=oracle]
    DECLARE
    NO INTEGER :=1;
    NUM INTEGER :=1;
    BEGIN
    for no in 1..10 loop
    for Num in 1..10 loop
    insert into result (difference) select (select T1.latitude from table1 T1 where sno=no - select T2.table2 from table2 T2 where sno=Num ) from table1 T1, table2 T2 ;
    end loop;
    end loop;
    END;[/code]

    Please help me in debugging this....
    thanks a lot
    Ashwini
    Last edited by debasisdas; Jan 28 '08, 10:36 AM. Reason: Formatted using code=oracle tag.
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Try to use cursor for the purpose.

    Comment

    • subashsavji
      New Member
      • Jan 2008
      • 93

      #3
      [code=oracle]

      DECLARE
      NO INTEGER :=1;
      NUM INTEGER :=1;
      BEGIN
      FOR no IN 10..10 LOOP
      FOR Num IN 10..10 LOOP
      INSERT INTO result (difference)
      VALUES((SELECT T1.DEPTNO FROM DEPT T1 WHERE DEPTNO=no) - (SELECT T2.DEPTNO FROM DEPT T2
      WHERE DEPTNO=Num )) ;
      END LOOP;
      END LOOP;
      END;
      /

      [/code]
      Last edited by amitpatel66; Jan 31 '08, 11:34 AM. Reason: code tags

      Comment

      • subashsavji
        New Member
        • Jan 2008
        • 93

        #4
        [code=oracle]

        DECLARE
        NO INTEGER :=1;
        NUM INTEGER :=1;
        BEGIN
        FOR no IN 1..10 LOOP
        FOR Num IN 1..10 LOOP
        INSERT INTO result (difference)
        VALUES((SELECT T1.latitude FROM table1 T1 WHERE sno=no) - (SELECT T2.LAT FROM table2 T2 WHERE s
        END LOOP;
        END LOOP;
        END;
        /

        [/code]
        Last edited by amitpatel66; Jan 31 '08, 11:34 AM. Reason: code tags

        Comment

        Working...