English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

DECLARE
TOT_SAL NUMBER:=0;
CURSOR CR1 IS SELECT ENAME,SAL FROM EMP;
BEGIN
FOR R1 IN CR1 LOOP
TOT_SAL := TOT_SAL + R1.SAL;
DBMS_OUTPUT.PUT_LINE(R1.ENAME||' '||LPAD(R1.SAL,9));
END LOOP;
DBMS_OUTPUT.PUT_LINE(' =============');
DBMS_OUTPUT.PUT_LINE('Total salary:'||TOT_SAL);
END;

Why i am not getting the total salary value?

2007-03-25 17:21:43 · 1 answers · asked by Maxood 3 in Computers & Internet Programming & Design

1 answers

1) DBMS_OUTPUT.PUT_LINE(R1.ENAME|... '||LPAD(R1.SAL,9)); is missing an ' and a | (ie || instead of |).

2) You might need DBMS_OUTPUT.ENABLE(); if you're not getting any output at all.

3) Does your table contain rows with a sal of NULL? X + NULL is not defined so you would always get a result of NULL at the end. To get around that (assuming that you want to treat NULL as 0), use
TOT_SAL := TOT_SAL + NVL(R1.SAL, 0); instead.

2007-03-29 13:54:58 · answer #1 · answered by Andrea 3 · 0 0

fedest.com, questions and answers