如果您不想捕获异常,请删除异常块!
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; /* do you really want to commit in a procedure? */
END myproc;
您不必全部捕获它们(例外不是口袋妖怪)。如果你真的坚持追赶和重新加注,你可以使用RAISE或RAISE_APPLICATION_ERROR:
EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20001 /* user-defined exception number
between -20999 and -20000 */,
'your user-defined exception message',
TRUE /* this will preserve the error stack */
);
END;
如果您想更具体并仅捕获子异常,则必须定义异常编号,因为PL/SQL 中没有针对此错误的预定义异常:
CREATE OR REPLACE PROCEDURE myproc(p_id NUMBER, p_id2 NUMBER, p_par3 NUMBER) AS
child_exists EXCEPTION;
PRAGMA EXCEPTION_INIT(child_exists, -2292); /* raises ORA-02292 */
BEGIN
DELETE FROM child_table
WHERE id1 = p_id
AND par = p_par3;
DELETE FROM parent_table WHERE no = p_id2;
COMMIT; /* do you really want to commit in a procedure? */
EXCEPTION
WHEN child_exists THEN
-- do something
RAISE;
END myproc;