Home » Developer & Programmer » Forms » Oracle sequence number in an ON-INSERT trigger
Oracle sequence number in an ON-INSERT trigger [message #159645] Mon, 20 February 2006 14:59 Go to next message
bdrufner
Messages: 42
Registered: August 2005
Location: Home of the Mardi Gras, N...
Member
Forms 9.2.4 (32 bit), RDBMS 9.2.0

I have a master-detail form. The master data block is based on one table [CLASS] and allows the user to populate the form with "class related" data ( class name, number of class hours, etc.). The detail block is based on another table [SESSION] and allows the user to populate the form with "session related" data (session name, session date, etc.). Typically, but not always, I have several sessions for every class.

I am using an Oracle sequence to populate my primary key (PK CLASS ID) for the CLASS table via an ON-INSERT trigger at the data block level for the CLASS data block. I have set the
property of the FK CLASS ID [SESSION data block] for "copy value from item" equal to the PK CLASS ID [CLASS data block].

When the user updates the form, both ON-INSERT triggers fire as typically the user is adding both CLASS and SESSION data. I have attached a partial copy of each trigger.

ON-INSERT trigger for CLASS data block:
begin
 insert into hrt_class(pk_class_id, fk_class_location_id,    fk_course_id ... )
 values(hrt_master_detail_seq.nextval, :db_hrt_class.fk_class_location_ id, :db_hrt_class.fk_course_id ... );
end;


ON-INSERT trigger for SESSION data block:
begin
 insert into hrt_session(fk_class_id,pk_session_type_id,	  fk_session_instructor_id ...)
 values( :db_hrt_session.fk_class_id, 	
	 :db_hrt_session.FK_SESSION_TYPE_ID,
	  :db_hrt_session.FK_SESSION_INSTRUCTOR_ID  );
end;


While the user completes the insert without error, the FK CLASS ID never gets populated with any value. I would like both the PK CLASS ID and the FK CLASS ID to have the same value as they are related this way, but it never happens. I have looked at it in the debugger and the value fo the FK CLASS ID is never populated (null).

Any comment, recommendation and/or solution is much appreicated.

Thanks in advance.

Barry
Re: Oracle sequence number in an ON-INSERT trigger [message #159697 is a reply to message #159645] Mon, 20 February 2006 23:43 Go to previous messageGo to next message
djmartin
Messages: 10181
Registered: March 2005
Location: Surges Bay TAS Australia
Senior Member
Account Moderator
Okay ... try this way ... lose the triggers, in the When-Create-Record for the 'CLASS' block populate the 'pk_class_id' item with 'hrt_master_detail_seq.nextval'. You will get gaps in the sequence if you don't save the 'CLASS' record but typically that is no problem. In the block definition for 'SESSION' set the default value for 'pk_class_id' to ':class.pk_class_id'.

Try that and get back to us.

David
Re: Oracle sequence number in an ON-INSERT trigger [message #159775 is a reply to message #159645] Tue, 21 February 2006 08:29 Go to previous message
bdrufner
Messages: 42
Registered: August 2005
Location: Home of the Mardi Gras, N...
Member
David,

I have tested your recommendation and your solution worked (as usual!). I have shared your solution with other developers in my group.

Many thanks. I appreciate your help.

Barry
Previous Topic: About Form Builder in Oracle 10g
Next Topic: asci report
Goto Forum:
  


Current Time: Fri Sep 20 07:35:19 CDT 2024