1. Home
  2. Docs
  3. Oracle 19c PL/SQL
  4. Exceptions
  5. Miscellaneous Examples

Miscellaneous Examples

Some exceptions can be handled in the executable part of a program.

DECLARE
  V_Deptno Dept.Deptno%TYPE;
  V_Sal Emp.Sal%TYPE;
BEGIN
  V_Deptno :=&GiveDeptno;
  V_Sal :=&GiveIncreaseSal;
  UPDATE Emp
   SET
   Sal =Sal+V_Sal
   WHERE Deptno = V_Deptno;
  IF SQL%NOTFOUND THEN
    DBMS_OUTPUT.PUT_LINE('Deptno Not Found. Delete is Unsuccessful.');
  ELSE
    DBMS_OUTPUT.PUT_LINE(SQL%ROWCOUNT||' rows updated.');
  END IF;
END;
/
Enter value for givedeptno: 30
Enter value for giveincreasesal: 100
6 rows updated.                                                                 

PL/SQL procedure successfully completed.

SQL> /
Enter value for givedeptno: 60
Enter value for giveincreasesal: 200
Denton Not Found. Delete is Unsuccessful.                                       

PL/SQL procedure successfully completed.

SQL> ROLLBACK;

Rollback complete.
Was this article helpful to you? Yes No

How can we help?