Age condition trigger [message #501149] |
Sat, 26 March 2011 08:24 |
|
snookian
Messages: 17 Registered: December 2010
|
Junior Member |
|
|
Hi i have this trigger linked to a button, but when i try it an error comes up on oracle application server form saying "FRM-40735: trigger raised unhandled exception ORA-01403"
declare
alert_button number;
age date;
ageless number;
begin
select date_of_birth
into age
from emp
where :social_security.person_id = emp.person_id;
ageless := months_between(sysdate, age)/12;
if (ageless <65) then
alert_button :=show_alert('ALERT_TOO_YOUNG');
if
alert_button =alert_button1 then
clear_record;
end if;
else go_item('SOCIAL_SECURITY.CATEGORY_ID');
end if;
end;
|
|
|
|
|
|
|
|
|
|
|
|
Re: Age condition trigger [message #501170 is a reply to message #501162] |
Sat, 26 March 2011 14:53 |
|
Littlefoot
Messages: 21823 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
This query (from your first message):
select date_of_birth
into age
from emp
where :social_security.person_id = emp.person_id; didn't find any record in the EMP table where EMP.PERSON_ID is equal to data block's :SOCIAL_SECURITY.PERSON_ID value.
How to test? When you run the form, you see (on the screen) :SOCIAL_SECURITY.PERSON_ID value. Remember it. Now open SQL*Plus and run the same SELECT statement, but this time substitute data block's item name with the value you remembered a moment ago. Imagine that :SOCIAL_SECURITY.PERSON_ID was 12345. You'd run
select date_of_birth
into age
from emp
where emp.person_id = 12345; That query won't return anything, so Oracle told you that there was no data found.
Question is: what do you want to do now? The right way would be to handle that exception properly (in EXCEPTION section), alerting user that person with that ID doesn't exist. Something like this:declare
alert_button number;
age date;
ageless number;
begin
begin
select date_of_birth
into age
from emp
where :social_security.person_id = emp.person_id;
exception
when no_data_found then
message('Employee does not exist');
raise form_trigger_failure;
end;
ageless := months_between(sysdate, age)/12;
if ageless < 65 then
alert_button :=show_alert('ALERT_TOO_YOUNG');
if alert_button = alert_button1 then
clear_record;
end if;
else
go_item('SOCIAL_SECURITY.CATEGORY_ID');
end if;
end;
While we're at it: note how my code is properly formatted, indented and easy to read. Try to format your code in your future messages.
|
|
|