Pre-insert block level, Seq.Nextval leaving gaps problem

Hi...form friends,
I used DB sequence in pre-insert block level trigger.
SELECT seq1.nextval INTO :abc.log_id FROM dual;
Everything works fine,except leaving gaps randomly .
It leaves around 10 no.s gaps in-between. And that happens randomly...
lets say I insert 5 records..then it will be 1,2,3,4,5.
Then it may jumps to 15,16,25 like...that....
I searched for this problem...but some say when form failure occurs, it leaves gap of CACHE no. specified....and some say its not possible to use DB seq. with forms perfectly ..!!!!
Anybody have any idea about this issue ???
Thanks....

Putting that functionality in a row level trigger will cause a mutating data exception.
Locking the table for update is not sufficient, you need to prevent other users inserting as well.
I've posted a method a few times before which uses dbms_lock and a table of serial numbers which is used in place of the oracle sequence. This provides maximum concurrency and allows for data to be rolled back, but there is obviously a payoff in terms of performance so it should only be used when absolutely necessary. There is a similar example in the link I posted above (which is a far more considered explanation than I've posted elsewhere!), along with some caveats about using gapless sequences and whether there is truly a need.
One of mine:
Re: On commit - sequence increases

Similar Messages

  • PRE-INSERT TRIGGER

    Dear All,
    In my pre-insert block Level triiger. I have the followed code.
    declare
    l_cnt pls_integer;
    cursor c1 is
    select count(1) into l_cnt
    from jnpp_barcode_master
    where organization_id = :ctrl_blk.inv_org_id
    and item_id = :jnpp_grv_lines.item_id
    and bar_code = :jnpp_grv_lines.bar_code
    and publication_date= :jnpp_grv_lines.publication_date;
    begin
         for r1 in c1 loop
              if l_cnt = 1 then
                   insert into jnpp_barcode_archive
                   (organization_id, item_id, bar_code, publication_date, po_list_price,
    selling_price, received_qty, reference, created_by, creation_date,
    last_updated_by, last_update_date)
    values (:ctrl_blk.inv_org_id, :jnpp_grv_lines.item_id, :jnpp_grv_lines.bar_code, :jnpp_grv_lines.publication_date, :jnpp_grv_lines.po_list_price,
    :jnpp_grv_lines.selling_price, :jnpp_grv_lines.qty, :jnpp_grv_lines.REFERNCE, :GLOBAL.X_USER_ID, sysdate,
    :GLOBAL.X_USER_ID, sysdate);          
              elsif l_cnt = 0 then
                        update jnpp_barcode_master
                        set publication_date = :jnpp_grv_lines.publication_date,reference =:jnpp_grv_lines.refernce
         where organization_id = :ctrl_blk.inv_org_id
         and item_id = :jnpp_grv_lines.item_id
         and bar_code = :jnpp_grv_lines.bar_code;
    end if;      
         end loop;
    forms_ddl('COMMIT');
    end;
    it is encountered the symbol 'INTO'.
    Im using forms 6i.
    please any one can help me.
    Thanks
    Siva

    declare
    l_cnt pls_integer;
    cursor c1 is
    select count(1) into l_cnt
    from jnpp_barcode_master
    where organization_id = :ctrl_blk.inv_org_id
    and item_id = :jnpp_grv_lines.item_id
    and bar_code = :jnpp_grv_lines.bar_code
    and publication_date= :jnpp_grv_lines.publication_date;
    begin
         for r1 in c1 loop
              if l_cnt = 1 then
                   insert into jnpp_barcode_archive
                   (organization_id, item_id, bar_code, publication_date, po_list_price,
    selling_price, received_qty, reference, created_by, creation_date,
    last_updated_by, last_update_date)
    values (:ctrl_blk.inv_org_id, :jnpp_grv_lines.item_id, :jnpp_grv_lines.bar_code, :jnpp_grv_lines.publication_date, :jnpp_grv_lines.po_list_price,
    :jnpp_grv_lines.selling_price, :jnpp_grv_lines.qty, :jnpp_grv_lines.REFERNCE, :GLOBAL.X_USER_ID, sysdate,
    :GLOBAL.X_USER_ID, sysdate);          
              elsif l_cnt = 0 then
                        update jnpp_barcode_master
                        set publication_date = :jnpp_grv_lines.publication_date,reference =:jnpp_grv_lines.refernce
         where organization_id = :ctrl_blk.inv_org_id
         and item_id = :jnpp_grv_lines.item_id
         and bar_code = :jnpp_grv_lines.bar_code;
    end if;      
         end loop;
    forms_ddl('COMMIT');
    end;
    --

  • Sequence number in pre-insert form trigger

    i have two tables invoice (master) inv_detail(detail) and assign the invoice number using a sequence number,
    by writing the folowing code in the pre-insert trigger
    select a.nextval into :inv_no from dual;
    ( i make the trigger at the form level becuause i have a master (invoice) and detail (inv_detail) relation at the same screen,so i must fetch the value of the
    sequence into the :invo_no in the screen,to let the 'copy value from' property at the detail block works so the value of the foreign key will be copied from
    the sequence number at the screen.
    will this method be a good one for multi user envirment(to select the a.nextval in the pre-insert trigger at the from level?)

    Kevin, thank you for the correct explanation. I was making an assumption and of course it was wrong.
    Mohannad, please do not try to link the invoice count with the sequence number. Any time you need a count, just do a select count(*). The sequence number is ONLY a unique key, and should represent nothing else.
    People have discussed this situation heavily. If you insist on trying to ensure there are no gaps, you will:
    1. Fail -- there are many scenarios where gaps will occur.
    2. Waste your time.
    3. Whatever process you build to try to prevent gaps will cause unnecessary overhead and work for the server, and in a multi-user environment, cause processing bottlenecks due to table locks.

  • Pre-Insert Trigger not firing

    Hi,
    I am using Oracle 10G DS with Oracle 11G XE. I tried PRE-INSERT Trigger with the Code given by Mr Hamid. However, its not working. Though, the WHEN-NEW-ITEM-INSTANCE works fine, I wish to use PRE-INSERT Trigger only.
    Can you please help me.
    My Code is shown below
    BEGIN
    SELECT asset_id_seq.nextval INTO :r_it_blk.asset_id
    FROM dual;
    END;
    Thanks in advance
    Ramesh

    Hi Hamid,
    Thank you very much for your reply.
    I tried at Block Level itself. Further, I also tried the below Code with Cursor (Block Level). Unfortunately, it is also not working. Even the Error Message is also not displayed. The User has full privileges.
    DECLARE
         CURSOR next_id IS SELECT asset_id_seq.NEXTVAL FROM dual;
    BEGIN
         OPEN next_id;
         FETCH next_id INTO :r_it_blk.asset_id;
         CLOSE next_id;
         IF :r_it_blk.asset_id IS NULL THEN
         Message('Error Generating Next Asset ID');
         RAISE Form_Trigger_Failure;
         END IF;
    END;
    Regards
    Ramesh

  • Pre insert ,,go_item

    Hi all
    i have created a new field in the existing table with data
    I have made the field as non mandatory .
    On the form i have added the field
    i want to make this field as mandatory now .
    hence i have added the code in the pre insert and pre update trigger .
    till here it works fine
    now i have written a go_item in the pre insert and pre update to navigate to the item after the error
    but it gives me error that go_item not allowed in preupdate .
    is there any workaround by which i can navigate to the item for entering the value if it is left blank ?
    plzz help me
    mandar

    So on new records and records where the user changes any field you want to make sure they have entered a value in a particular field. The best way to do this is to use the 'Required' property.
    I created a new form (forms 10.1.2) with a block based on the EMP table, and set the COMM item to 'Required'. This column is non-mandatory in the database and has a mixture of null and not-null entries, just like yours. In the when-validate-item trigger at block level I used this:
    Set_Item_Property('EMP.COMM',ITEM_IS_VALID,PROPERTY_FALSE);so if the record is changed then the COMM item will be validated when the user moves away from the record.
    The default behaviour is for forms to move the cursor to the null field and prompt the user. To change that prompt, I changed the block-level on-error trigger to this:
    DECLARE
     lv_errcod NUMBER := ERROR_CODE;
     lv_errtyp VARCHAR2(3) := ERROR_TYPE;
     lv_errtxt VARCHAR2(80) := ERROR_TEXT;
    BEGIN
     IF (lv_errcod = 40202) THEN
      /* field must be entered */
      IF :system.trigger_item = 'EMP.COMM' THEN
       message('Please enter a Commission value',acknowledge);
      ELSIF :system.trigger_item = 'EMP.EMPNO' THEN
       message('Please enter an Employee Number',acknowledge);
      ELSE
       message('Please enter a value for '||:system.trigger_item,acknowledge);
      END IF;
     ELSE Message(lv_errtyp||'-'||to_char(lv_errcod)||': '||lv_errtxt);
      RAISE Form_Trigger_Failure;
     END IF;
    END;It works fine. The only functional difference between my approach and yours is that I warn the user when they leave the record and you warn them when they save the record.
    On using the pre-insert trigger for this, I'd say that it's usually not a good idea to validate in triggers other than the validation triggers (eg when-validate-record) or to override the forms default validation.

  • Problem with forms6i using Pre-Insert Trigger

    I created a block level pre-insert trigger to do some validations and when I save the first time with wrong data it is working fine and popping up alerts that I defined but if I press save the second time it is saving even though the data is wrong.
    This is in Applications 11.5.10 using all the property classes and running on the server.
    I created exact replica of the form(no applications, property classes
    just basic form but with same functionality) and ran it on my local machine it is working fine. It is giving error till the data is fixed.
    Anybody know why?
    Thanks in advance

    It did not work. It is still doing the samething. Actually it is popping up my alerts but saving the record first time itself. Is there any way I can tell it not to save if the data is wrong. My code is below it basically pops up the alerts but doesn't tell anywhere not to save it.
    Thanks
    VJ
    declare
         v_amount number;
         alert_id      ALERT := Find_Alert('amount_from');
         alert_id1 ALERT := Find_Alert('amount_to');
         dummy_var NUMBER;
    begin
         select max(ssibe_amount_to) into v_amount from ssibe_orderappr_tab where
              ssibe_account_number = :ssibe_orderappr.ssibe_account_number;
              if :ssibe_orderappr.ssibe_amount_from <= v_amount
              then
                   Set_Alert_Property(alert_id, ALERT_MESSAGE_TEXT, 'Amount_From should be greater than '|| v_amount);
                   dummy_var := Show_Alert(alert_id);
              else
                   IF (:SSIBE_ORDERAPPR.SSIBE_AMOUNT_TO <= :SSIBE_ORDERAPPR.SSIBE_AMOUNT_FROM)
                   THEN
                   dummy_var := Show_Alert(alert_id1);
                   end if;
              end if;
    end;

  • Pre-insert-trigger ignoring assignments

    Hi,
    I have this code in a PRE-INSERT-TRIGGER of a database table block:
    Select emp_seq.Nextval Into :EMP.EMPNO From dual;
    Select Sysdate Into :EMP.LASTCHANGED From dual;
    And i have this code in a PRE-UPDATE-TRIGGER of the same block:
    Select Sysdate Into :EMP.LASTCHANGED From dual;
    given scenario:
    1) query records from the table into a block:
    empno ename lastchanged
    1 Smith 01.12.2008
    2 Johnson 01.12.2008
    2) change empname in any record except no. 1:
    empno ename lastchanged
    1 Smith 01.12.2008
    2 Johannson 01.12.2008
    3) create a new record somewhere above the changed record
    empno ename lastchanged
    1 Smith 01.12.2008
    <null> <null> <null>
    2 Johannson 01.12.2008
    4) insert ename in new record
    empno empname lastchanged
    1 Smith 01.12.2008
    <null> Obama <null>
    2 Johannson 01.12.2008
    5) do_key('commit_form')
    with Forms 6.0.8.23.2 -> working fine
    with Forms 6.0.8.27.0 -> ORA-01400:: cannot insert NULL into ("EMP"."EMPNO")
    Any assignment in the pre-insert-trigger is ignored! Can anyone help me with this bug? Thanks in advance

    message(:EMP.EMPNO) is always Null ...
    Everything works if there's no update of a record with higher record-number in the transaction. But the scenario in post 1 doesnt work with Forms 6.0.8.27.0Ugh -- that's ugly!
    Unfortunately, opening a Service Request with Oracle will get you nowhere, since Oracle no longer supports Forms 6i.
    Yesterday, I experienced something very similar with the same version of Forms, specifically this part: Everything works if there's no update of a record with higher record-number in the transaction.*
    If I updated a higher record number in the block, I could NOT get Forms to subsequently store a value in a column in a prior record. I would set the value in the column, and immediately display the value, and it was null! Fortunately in my case, the stored value was only to enable skipping a database lookup in a subsequent pass, so I just skipped working on a solution.
    However, in your case, the problem is a show-stopper.
    What I found was that if I navigated back to the first record in the block, the problem went away. So maybe try this in your commit process:
        Go_block('ABC');
        First_Record;
        Synchronize;
        Commit_Form;Let us know if that works for you.

  • Post-insert vs pre-insert

    Dear All,
    can anybody explain the difference b/w pre-insert and post-insert trigger ?
    i need such example which process something that becomes possible in one trigger and no possible in other ?
    Regards
    Kashif Butt

    Here is an example. Please remove any syntax errors before running :-)
    create sequence my_seq;
    create table table_a
    (id number(20) constraint pk_table_a primary key,
    text varchar2(100)
    create table table_b
    (id number(20) constraint pk_table_b primary key,
    a_id number(20) constraint fk1_table_b foreign key references table_a(id),
    text varchar2(100)
    Create a form with a block based on table_a with items "id" and "text"
    "id" is on null canvas (not visible), put "text" on a canvas.
    pre-insert:
    select my_seq.nextval into :table_a.id;
    This can't be done in post-insert. Then the insert will fail because it's the primary key and must be "not null"
    post-insert:
    insert into table_b(id, a_id, text)
    values(my_seq.nextval, :table_a.id, 'Inserted automatically by post-insert');
    This can't be done in the pre-insert trigger, because the foreign key constraint will require the record in table_a
    to be inserted first.

  • Block Level Sequenece

    Hi All,
    How can we create block level sequences,and which type of trigger we have use.
    i have created DB level trigger,but it is not inserting in DB.
    If any one is having the coding you can plss send me sir,
    this is very urget
    Thanks,
    Siva

    i have created DB level trigger,but it is not inserting in DB.It might help if you explain more about what you've done and what didn't work.
    You can use :sequence.my_seq.nextval in the Initial Value property of an item to default it to a sequence value.

  • Pre-insert trigger is not firing after post built-in

    Hi,
    I have a 10g form in which Post built-in is used in When-button-pressed Trigger. After the post command I am checking some condition,by using the same record which I have posted.But it is not working.
    I have also put the message in the pre-insert trigger but the message is not displaying.
    But the same form iis working fine in form 6i, as I have migrated the forms from form 6i to 10g.

    Yes, In that block there are other items also. I have made the required property no for all the items.
    what exactly we have is
    (if x=y then)on some condition check
    POST;
    After that, form have a select statement in which it is selecting the same row which is being posted above.
    if the select statement gives count of row zero
    raise form_trigger_failure is fired.
    and in the pre-insert trigger form is assigning a value to a block item.

  • MAX + 1 Pre Insert

    Dear All
    i need to use MAX+1 instead of Sequence value in Pre Insert trigger in ADF / JSF Application ..
    and this value assigned to PK Attribute
    i unchecked Mandatory value for PK
    my problem now, system give me the value is required when i try to enter second record without commit first record as i have af:table , and i guess that it read the validation before pre insert trigger in dodml
    if (operation == DML_INSERT) {
    setContractId(GetSequenceValue("customers", "customer_id"));
    thanks
    Edited by: user8854969 on Dec 13, 2012 11:42 PM

    Tell your client to ignore the gaps...
    If you want a gapless number, you have 2 basic options:
    1). Assign the gapless number in a batch process after-the-fact
    2). Use an approach that serialises (i.e. only allows one insert at a time), by using locking or some other serialisation method. This approach limits your scalability.
    I have (almost always) used option 3: Use a sequence and ignore the fact that there are gaps. I the case where I didn't use this option, I used approach 2. You cannot do this with a trigger!
    John

  • Writing PRE-INSERT trigger in CUSTOM.pll

    Hi,
    We need to write data in a staging table after every save of a Block Data on the eBusiness Center form. How can we achieve this? Can we write PRE-INSERT trigger in CUSTOM.pll.
    Thanks for helping,
    Regards,
    Viral

    Hi. Thanks for the reply. I was trying with Workflow Based Business Events. I am not sure how can I achieve the same with it.
    I was thinking of doing the same using ALERTs. But, I think that is not Oracle suggestable method of doing it? If at all I am going to use the ALERTs than will it be real time?
    Thanks for replying,
    Regards,
    Viral.
    Message was edited by:
    Viral

  • Date Format Issue with Pre-Insert trigger

    I have created a form wherein creation_date and last_update_date are columns in a table that needs to be populated with sysdate (in format mm/dd/yyyy hh:mi:ss am) at time of saving.
    In pre-insert triiger, if I assign date as follows , it works:
    :creation_date=sysdate;
    However this creates date in format yyyy/mm/dd.
    I would like to set it in format mm/dd/yyyy hh:mi:ss am.
    How can this be done-I tried using to_date and to_char but wont work.
    Any ideas?

    hi
    u may try this too.
    when-new-form-instance trigger:
    set_application_property(PLSQL_date_FORMAT,'DDMMYYYY HH12:MI:SS');
    set_application_property(BUILTIN_date_FORMAT,'DDMMYYYY HH12:MI:SS');
    forms_ddl('ALTER SESSION SET NLS_date_FORMAT=''DDMMYYYY HH12:MI:SS'''); sarah

  • When-validate-item firing on block level.

    Hi all
    i have six fields and when-validate-item trigger is working on block level, i want to display records in one field,i want when-validate-item trigger work on item level not on block level,any help will be greatly appreciated.
    here is the code.
    When-Validate-Item Trigger.
    declare
         Str_Space VARCHAR2(20);
    begin
    Str_Space := ' ';
    :ins1.ref := :ins1.branch || Str_Space || :ins1.class || Str_Space || :ins1.year || Str_Space || :ins1.serial || Str_Space || :ins1.cno || Str_Space || :ins1.edno;
    end;
    sarah

    Francois Degrelle.
    just look the following code.
    DECLARE
         Str_Space VARCHAR2(20);
    begin
         Str_Space := ' ';
    :ins1.ref := :ins1.branch || Str_Space || :ins1.class || Str_Space || :ins1.year || Str_Space || :ins1.serial || Str_Space || :ins1.cno || Str_Space || :ins1.edno;
    END;
    by using the above code i am passing branch,class,year,serial,cno and edno to Ref column( 1 G01 2009 13112 00 01). and Str_space variable is creating space for each item.i want the above code work at item leavel instead of block level.Is it poassibl?
    sarah

  • Unable to insert the record to table using pre-insert & pre-update trigger

    Hi All,
    I have tried to insert and update the backend table using the pre-update and pre-insert triggers. But its not working for me. Please find below the code which i have used in the triggers.
    Pre-insert trigger:
    DECLARE
    v_cust_num_cnt NUMBER;
    BEGIN
              SELECT      COUNT(customer_number)
              INTO      v_cust_num_cnt
              FROM cmw_bc_mobile_number
              WHERE substr(customer_number,1,15)=substr(:BLOCKNAME.CUSTOMER_NUMBER,1,15);
              IF      v_cust_num_cnt = 0 THEN
                        INSERT INTO cmw_bc_mobile_number (CUSTOMER_NUMBER
                                                                                                   ,MOBILE_NUMBER
    ,CREATION_DATE
    VALUES
    (substr(:BLOCKNAME.CUSTOMER_NUMBER,1,15)
    ,:BLOCKNAME.MOBILE_NUMBER
    ,SYSDATE
    COMMIT;                                                                                                    
    END IF;          
    END;
    PRE_UPDATE TRIGGER:
    BEGIN
              IF :SYSTEM.RECORD_STATUS = 'CHANGED' THEN
              UPDATE apps.cmw_bc_mobile_number
         SET mobile_number = :BLOCKNAME.MOBILE_NUMBER,
         creation_date = SYSDATE
              WHERE customer_number=substr(:BLOCKNAME.CUSTOMER_NUMBER,1,15);
              COMMIT;
         END IF;
    EXCEPTION
              WHEN OTHERS THEN
                   NULL;     
    END;
    Please let someone assist in gettting it resolved.
    Regards,
    Raj.

    Just use MESSAGE (we don't know what fnd_message is, that is some custom code):
    message('v_cust_num_cnt='||v_cust_num_cnt);
    IF v_cust_num_cnt = 0 THEN
      message('Now inserting...');
      INSERT INTO cmw_bc_mobile_number (CUSTOMER_NUMBER... 
    else
      message('Nothing to insert');
    end if;

Maybe you are looking for

  • How can i access dmz server via public ip from inside?

    hi all ! As shown in Figure,how can i access the server in dmz zone via public? i can access it via private ip 192.168.1.1 now,but i can't access it via 101.100.1.2. who can help me ? thank you !

  • UIImpersonator tests work in FlashBuilder, but not when run from Ant

    I'm in the process of converting a Flex 3 project to use FlexUnit4 tests. Everything compiles in Flashbuilder 4.5 and runs nicely. I've converted all the tests to use flexunit 4, which highlighted a few issues, but nothing too major, and all the test

  • Customer wise TDS Receivable Report

    hi, Our Client requirement is to get customer wise TDS Receivable Report. As of now they are passing manual entry whenever they get the TDS certificate from the customer. Is it possible to configure in SAP to pass automatic entry for TDS receivable r

  • Mx 410 prints one page {as wanted} then spits out 7 blank pages Why ??

    This happens when i use page setup in print preview to resize the image. Print dialog box indicates  all pages as selected Not able to make any other selection.  Display of print que shows 8 pages to print.  One page of image is printed, (as wanted} 

  • The skype 7.4.99.102 encounter memory leak problem

    When I open skype for an hour, the skype pop up a message "Not enough storage is available to process this command." Now the memomry of skype is exceed 1G. Please fix the issue. The error and system information is attached. Attachments: skype_memory_