The DELETE statement available in the SQL language can also be used in SPL programs.
An expression in the SPL language can be used wherever an expression is allowed in the SQL DELETE statement. Therefore, SPL variables and parameters can be used to supply values to the delete operation.
CREATE OR REPLACE PROCEDURE emp_delete (
p_empno IN emp.empno%TYPE
)
IS
BEGIN
DELETE FROM emp WHERE empno = p_empno;
IF SQL%FOUND THEN
DBMS_OUTPUT.PUT_LINE('Deleted Employee # : ' || p_empno);
ELSE
DBMS_OUTPUT.PUT_LINE('Employee # ' || p_empno || ' not found');
END IF;
END;
If a row is deleted, the SQL%FOUND conditional expression returns TRUE. Otherwise, the expression returns FALSE.
EXEC emp_delete(9503);
Deleted Employee # : 9503
SELECT * FROM emp WHERE empno = 9503;
empno | ename | job | mgr | hiredate | sal | comm | deptno
-------+-------+-----+-----+----------+-----+------+--------
(0 rows)