Pre-Insert of Data Block doesn't work for me. [message #425376] |
Thu, 08 October 2009 17:34 |
fredg
Messages: 8 Registered: October 2009 Location: NZ
|
Junior Member |
|
|
Hello everyone, I am a newbie in Oracle Forms, really need help to figure out the issue of Pre-insert trigger.
I created form DEPT by following a tutorial, then data block DEPARTMENT was generated by data block wizard. at this stage, I got everything runs well, data appears correctly. So I want to use an Oracle Sequence in datablock which should generate & display the new ID in the field when user click on icon "Insert Record"on toolbox.
Firstly, the auto_sequence runs correctly by SQL*PLUS
*********************************************
select DEPT_ID_SEQ.nextval from DUAL;
*********************************************
Then I insert code as follows in trigger PRE-INSERT of DATA BLOCK.
*****************************************************
type: trigger
object: department - Data Block Level
*****************************************************
begin
select DEPT_ID_SEQ.nextval
into :DEPARTMENT.ID
from DUAL;
end;
****************************************************
finally, I save + compile module + run form, I didn't see an auto-generated ID in the ID field once I clicked the icon "insert records".
Then I made a button call "New ID", then inserted the code above into button's trigger "WHEN-BUTTON-PRESSED", re-run the form, it works!
For my understand, the icon "Insert Record" on toolbar doesn't active the trigger "PRE-INSERT".
Why?
[EDITED by LF: removed superfluous empty lines]
[Updated on: Fri, 09 October 2009 00:52] by Moderator Report message to a moderator
|
|
|
|
Re: Pre-Insert of Data Block doesn't work for me. [message #425685 is a reply to message #425400] |
Sun, 11 October 2009 15:47 |
fredg
Messages: 8 Registered: October 2009 Location: NZ
|
Junior Member |
|
|
Hi Littlefoot, you are the champion! the guru! The trigger WHEN-CREATE-RECORD does work well, we should not use WHEN-NEW-RECORD-INSTANCE in this case, otherwise, these existing record willbe assigned a new ID once we click PREV or NEXT button on toolbar. I wonder why these books indicated to trigger PRE-INSERT.
I appreciate so much for your help.I am sure that I will be visiting this forum regularly, wise to provide assistance to someone once I gain the ability.
[Updated on: Sun, 11 October 2009 16:15] Report message to a moderator
|
|
|
Re: Pre-Insert of Data Block doesn't work for me. [message #425736 is a reply to message #425685] |
Mon, 12 October 2009 01:07 |
|
Littlefoot
Messages: 21823 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
As of not using WHEN-NEW-RECORD-INSTANCE trigger: well, you can overcome the problem by verifying whether ID item is null and - if so - setting its value. Something like
if :department.id is null then
select DEPT_ID_SEQ.nextval
into :DEPARTMENT.ID
from DUAL;
end if; Doing so, you wouldn't overwrite existing ID values.
|
|
|