I have a plsql procedure to delete records from child and parent tables.
I would like to raise exception when child record found.
How can I do this?
CREATE OR REPLACE PROCEDURE myproc(
p_id number,
p_id2 number,
p_par3 number)
AS
BEGIN
DELETE FROM child_table
WHERE id1 = p_id and par=p_par3;
DELETE FROM parent_table
WHERE no = p_id2;
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
--raise
END myproc;
/
Remove the exception block if you don’t want to catch the exception !
You don’t have to catch them all (exceptions are not pokemon). If you really insist on catching and re-raising you can use RAISE or RAISE_APPLICATION_ERROR:
If you want to be more specific and trap only the child exception, you will have to define the exception number because there is no predefined exception in PL/SQL for this error: