Results 1 to 2 of 2

Thread: SUM at DBMS_OUTPUT.PUT_LINE

  1. #1
    Join Date
    May 2009
    Posts
    7

    Question 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
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932

Posting Permissions

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