Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2004
    Location
    Cergy
    Posts
    65

    Unanswered: pl/sql in a cursor, hom can I sum ?

    DECLARE
    v_debit number(16,2);
    BEGIN
    FOR c_pra IN (SELECT cosite,dagene,nobord,sum(soprel)
    FROM lc_pra group by cosite,dagene,nobord)
    loop
    v_debit:=soprel; <====HOW CAN I GET THE SUM ?
    end loop;
    end;

    ==========
    I want to sum the field soprel in a variable v_debit.
    I have created a cursor with a group by.
    bu Hom can I get the sum in my variable . I don't know the syntax.

    Thanks

  2. #2
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1

    Re: pl/sql in a cursor, hom can I sum ?

    You need to give the sum(soprel) column an alias:

    FOR c_pra IN (SELECT cosite,dagene,nobord,sum(soprel) sum_soprel
    ...

    Then you can use this in the loop:

    v_debit := c_pra.sum_soprel;

    Of course, within the loop there is no need to assign c_pra.sum_soprel to another variable. You can just use c_pra.sum_soprel directly.

  3. #3
    Join Date
    Jan 2004
    Location
    Cergy
    Posts
    65

    Re: pl/sql in a cursor, hom can I sum ?

    It works !!!
    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •