SET SERVEROUTPUT ON
SET VERIFY OFF
SET ECHO OFF
ACCEPT p_num PROMPT 'Please enter the number of top money makers: '
DECLARE
Wrong_Input EXCEPTION;
v_num NUMBER(2) := &p_num;
v_ename emp.ename%TYPE;
v_sal emp.sal%TYPE;
v_dept dept.dname%TYPE;
tmp_sal emp.sal%TYPE;
v_count Number;
CURSOR emp_cursor IS
SELECT emp.ename, emp.sal, dept.dname
FROM emp , dept
WHERE emp.sal IS NOT NULL
and emp.deptno = dept.deptno
ORDER BY emp.sal DESC;
BEGIN
Select count(*)
into v_count
from EMP;
If (v_num <= 0) or (v_count < v_num) Then
RAISE Wrong_Input;
End if;
OPEN emp_cursor;
FETCH emp_cursor INTO v_ename, v_sal, v_dept;
tmp_sal := 0;
DBMS_OUTPUT.PUT_LINE('NAME DEPARTMENT SALARY');
DBMS_OUTPUT.PUT_LINE('---- ---------- -------');
WHILE emp_cursor%ROWCOUNT <= v_num AND emp_cursor%FOUND LOOP
DBMS_OUTPUT.PUT_LINE(rpad(v_ename, 20) || rpad(v_dept, 20) || lpad(TO_CHAR(v_sal), 7));
FETCH emp_cursor INTO v_ename, v_sal,v_dept;
If tmp_sal = v_sal Then
v_num := v_num + 1;
else
tmp_sal := v_sal;
End If;
END LOOP;
CLOSE emp_cursor;
EXCEPTION
WHEN Wrong_Input THEN
DBMS_OUTPUT.PUT_LINE('*** Input must be in between 1 to ' || v_count || '. Please try again! ***');
END;
/
SET VERIFY ON
SET ECHO ON
////////////////// OutPut //////////////////////////
Please enter the number of top money makers: 5
NAME DEPARTMENT SALARY
---- ---------- -------
KING ACCOUNTING 5000
FORD RESEARCH 3000
SCOTT RESEARCH 3000
JONES RESEARCH 2975
BLAKE SALES 2850
CLARK ACCOUNTING 2450
PL/SQL procedure successfully completed.
Input truncated to 11 characters
////////////////// QUESTIONS //////////////////////////
Why last line of output has "Input truncated to 11 characters" that kind of message??
SET VERIFY OFF
SET ECHO OFF
ACCEPT p_num PROMPT 'Please enter the number of top money makers: '
DECLARE
Wrong_Input EXCEPTION;
v_num NUMBER(2) := &p_num;
v_ename emp.ename%TYPE;
v_sal emp.sal%TYPE;
v_dept dept.dname%TYPE;
tmp_sal emp.sal%TYPE;
v_count Number;
CURSOR emp_cursor IS
SELECT emp.ename, emp.sal, dept.dname
FROM emp , dept
WHERE emp.sal IS NOT NULL
and emp.deptno = dept.deptno
ORDER BY emp.sal DESC;
BEGIN
Select count(*)
into v_count
from EMP;
If (v_num <= 0) or (v_count < v_num) Then
RAISE Wrong_Input;
End if;
OPEN emp_cursor;
FETCH emp_cursor INTO v_ename, v_sal, v_dept;
tmp_sal := 0;
DBMS_OUTPUT.PUT_LINE('NAME DEPARTMENT SALARY');
DBMS_OUTPUT.PUT_LINE('---- ---------- -------');
WHILE emp_cursor%ROWCOUNT <= v_num AND emp_cursor%FOUND LOOP
DBMS_OUTPUT.PUT_LINE(rpad(v_ename, 20) || rpad(v_dept, 20) || lpad(TO_CHAR(v_sal), 7));
FETCH emp_cursor INTO v_ename, v_sal,v_dept;
If tmp_sal = v_sal Then
v_num := v_num + 1;
else
tmp_sal := v_sal;
End If;
END LOOP;
CLOSE emp_cursor;
EXCEPTION
WHEN Wrong_Input THEN
DBMS_OUTPUT.PUT_LINE('*** Input must be in between 1 to ' || v_count || '. Please try again! ***');
END;
/
SET VERIFY ON
SET ECHO ON
////////////////// OutPut //////////////////////////
Please enter the number of top money makers: 5
NAME DEPARTMENT SALARY
---- ---------- -------
KING ACCOUNTING 5000
FORD RESEARCH 3000
SCOTT RESEARCH 3000
JONES RESEARCH 2975
BLAKE SALES 2850
CLARK ACCOUNTING 2450
PL/SQL procedure successfully completed.
Input truncated to 11 characters
////////////////// QUESTIONS //////////////////////////
Why last line of output has "Input truncated to 11 characters" that kind of message??