Supprimez le bloc d'exception si vous ne voulez pas intercepter l'exception!
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;
Vous ne devez pas les attraper tous (exceptions are not pokemon). Si vous insistez vraiment sur la capture et sur-relançant vous pouvez utiliser RAISE ou 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;
Si vous voulez être plus précis et un piège que l'exception des enfants, vous devrez define the exception numéro parce qu'il n'y a pas predefined exception dans PL/SQL pour cette erreur:
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;
est-il possible d'avoir quelque chose comme ça dans myproc? 'PRAGMA EXCEPTION_INIT (foreign_key_violated, -02291);' Pourriez-vous être assez aimable pour suggérer ce qui se passerait si commit existe dans une procédure? – user75ponic
Bien sûr, même si je pense qu'une suppression va élever un 'ORA-02292', voir ma mise à jour. Pour en savoir plus sur les exceptions définies par l'utilisateur: http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/errors.htm#i3329 –
Merci pour l'information. Apprécié. – user75ponic