Hi All,
I was just browsing across the new edition of Steven's book and was reading about exception handling part, I just wondered if we could handle exception for update statement with when others then
BEGIN
UPDATE emp
SET sal=5000
WHERE empno = 8000;
EXCEPTION WHEN OTHERS THEN
dbms_output.put_line('Update Failed-'||sqlerrm);
END;
Output:
How I handle it
DECLARE
p_count NUMBER;
BEGIN
UPDATE emp
SET sal = 5000
WHERE empno = 8000;
p_count := SQL%ROWCOUNT;
IF p_count = 0
THEN
DBMS_OUTPUT.put_line ('Update Failed-' || p_count || ' rows updated');
END IF;
END;
Output:
Update Failed-0 rows updated
Is this the right approach to handle exception for an update statement?
Please advise!
Thanks!