Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2009
    Posts
    20

    Question Unanswered: SUM at DBMS_OUTPUT.PUT_LINE

    DECLARE
    CURSOR emp_cur IS
    SELECT ename, sal
    FROM emp
    WHERE deptno = 10
    ORDER BY sal DESC;
    BEGIN
    FOR emp_rec IN emp_cur LOOP
    DBMS_OUTPUT.PUT_LINE ('Employee ' || emp_rec.ename || ' earns ' || TO_CHAR (emp_rec.sal) || ' dollars.');
    END LOOP;
    END;
    /

    This program generates the following output when executed in SQL*Plus:

    Employee KING earns 5000 dollars.
    Employee SCOTT earns 3000 dollars.
    Employee JONES earns 2975 dollars.
    Employee ADAMS earns 1100 dollars.
    Employee JAMES earns 950 dollars.

    How can I have the sum of emp_rec.sal on the last output line?
    Thanks.

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    sum_sal := sum_sal + emp_rec.sal;
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

Posting Permissions

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