Home » SQL & PL/SQL » SQL & PL/SQL » exception
exception [message #39124] Tue, 18 June 2002 10:04 Go to next message
rao
Messages: 25
Registered: July 1999
Junior Member
is there any expection for parent/foreign key voilation
if yes, can you give an example.

appreciate any help
Re: exception [message #39126 is a reply to message #39124] Tue, 18 June 2002 11:52 Go to previous message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
Here's a little block that shows how you can set up exceptions using the two common parent/child errors (-2291 and -2292) and then test specifically for these errors in the exception handler:

declare
  e_parent_key_not_found  exception;
  pragma exception_init(e_parent_key_not_found, -2291);
   
  e_child_record_found    exception;
  pragma exception_init(e_child_record_found, -2292);
begin
  -- enter a child record with an invalid parent id
  -- try to delete a parent with associated children and no ON DELETE CASCADE
exception
  when e_parent_key_not_found then
    dbms_output.put_line( 'The foreign key is invalid' );
  when e_child_record_found then
    dbms_output.put_line( 'This parent row has associated child rows' );
end;
Previous Topic: Re: Error in reading CLOB
Next Topic: Best methode to cache data in packages?
Goto Forum:
  


Current Time: Fri Mar 29 02:22:52 CDT 2024