Results 1 to 7 of 7

Thread: Average Cursor

  1. #1
    Join Date
    Feb 2004
    Posts
    3

    Unanswered: Average Cursor

    I Have something like this...

    CURSOR my_cursor IS
    SELECT avg(a),avg(b), avg(c), avg(d)
    FROM sch.mytable;

    How would i fetch this into a ROWTYPE variable? I keep getting null back.

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

    Re: Average Cursor

    You need to alias those avg columns:
    PHP Code:
    DECLARE
      
    CURSOR my_cursor IS
      SELECT avg
    (aavg_a,avg(bavg_bavg(cavg_cavg(davg_d
      FROM sch
    .mytable;
      
    my_row my_cursor%ROWTYPE;
    BEGIN
      OPEN my_cursor
    ;
      
    FETCH my_cursor INTO my_row;
      
    CLOSE my_cursor;
    END

  3. #3
    Join Date
    Feb 2004
    Posts
    3
    I do that, but i get "(1): PLS-00402: alias required in SELECT list of cursor to avoid duplicate column names". Im not sure why.

  4. #4
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1
    Originally posted by mjm461
    I do that, but i get "(1): PLS-00402: alias required in SELECT list of cursor to avoid duplicate column names". Im not sure why.
    That's what you get if you don't do that! Please post your full code.

  5. #5
    Join Date
    Feb 2004
    Posts
    3
    Sorry, i cant post it. I add that line in declare i get an error. even if i dont use the open, fetch, close lines. im sure its something im doing cuz im a beginner.

  6. #6
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1
    When I said "post it" I meant cut and paste it here. You can do that, surely? Impossible to debug code that we can't see!

  7. #7
    Join Date
    Jan 2004
    Posts
    492
    Originally posted by andrewst
    When I said "post it" I meant cut and paste it here. You can do that, surely? Impossible to debug code that we can't see!
    Gotta agree with Andrew. When fetching into a rowtype or table you must have unique column names. Giving an alias as he provided will take care of that error. Oracle is having trouble determining which column to fetch into the ROWTYPE variable.

Posting Permissions

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