Currently I have this PL/SQL function inside a package:
function populate_booking_map( pi_event_id in varchar2
,pi_status in number
,pi_booking_id in varchar2
)
return integer as
begin
insert into booking_map (
booking_id
,event_id
,currentstatus
)
values(
pi_booking_id
,pi_event_id
,pi_status
);
return c_success;
exception
when OTHERS then
log_error_msg( pi_app_name => c_application_name
,pi_error_msg => 'Exception in populate booking map.'
,pi_error_details => sqlerrm
);
return c_failure;
end populate_booking_map;
I want to add catching another exception - DUP_VAL_ON_INDEX - before OTHERS to handle exception when the attempt-to-insert record already exists in table.
Inside the handler, I want to check the existing values are same as the provided, i.e.: pi_booking_id=booking_id and pi_event_id=event_id and pi_status=currentstatus .
If they are completely the same, return c_success;.
If they are not the same, return c_failure;
How should I do that? Can I a SELECT query inside the exception handling? I have never seen anybody doing that.