Oracle Forms question

anumoses
anumoses used Ask the Experts™
on
Oracle form question

I have 2 new fields added. comment_user and comment_date.

Requirement

when the user enter comments in the vend_change_comments field, I have to populate comment_user as user and comment_date as sysdate.

In the forms pre-update trigger I have this code.. If the old user and old date is not the same as present user and date, the update it to user and sysdate. I have this code, which is not working. Need help

declare
	
	v_old_comment_user    dss.disposition_details.comment_user%TYPE;
	v_old_comment_date    dss.disposition_details.comment_date%TYPE; 
	
	Cursor C1 is
	select comment_user,comment_date
	  from dss.disposition_details
	 where id = :disposition_details.id
	   and action = 'R';
	  
Begin
	Open C1;
	Fetch C1 into v_old_comment_user
	              ,v_old_comment_date;
	Close C1;
	
If v_old_comment_user is null and v_old_comment_date is null then
		:disposition_details.comment_user := user;
	  :disposition_details.comment_date := sysdate;	
Elsif v_old_comment_user != :disposition_details.comment_user then
    	:disposition_details.comment_user:= user; 
ElsIf v_old_comment_date != :disposition_details.comment_date then
    		:disposition_details.comment_date := sysdate;
End if;  
    	
	
End;

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
flow01IT-specialist

Commented:
" is not working " means does not compile,  does compile and gives an error at runtime,  does compile and gives no error but is not updating comment_user.
If the last one is true verify  the trigger fires (put a message after the begin and if it does fire put additional messages with the value of the items that matter to  debug the problem), else give the error message for compile or runtime
Most Valuable Expert 2012
Distinguished Expert 2018
Commented:
>>If the old user and old date is not the same as present user and date

Sounds like the end result is set current user and date no matter what.  Why even perform the check?  Just set them.

If userA adds a comment today.  Then comes back again tomorrow and adds another, why could the date remain today?

If you need history, create dss.disposition_details_history table and put a table trigger on dss.disposition_details that inserts the current records into disposition_details_history.

Should simplify the form logic.
Mark GeerlingsDatabase Administrator
Commented:
I agree with slightwv's suggestion to just: "set current user and date no matter what.  Why even perform the check?"

If you do want to perform the check for some reason, there is a more efficient way to do that in Oracle Forms and avoid having to query the record in your pre-insert trigger:
1. Add two non-base-table, non-displayed fields in your block named: old_comment_user and old_comment_date (with data types that match your existing base-table fields).
2. Add a post-query trigger to set the values of:
    :disposition_details.old_comment_user := :disposition_details.comment_user;
    :disposition_details.old_comment_date := :disposition_details.comment_date;
3. Then your pre-update trigger can just compare the values of data already in the form with no extra query required.

Author

Commented:
thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial